2012-07-31 3 views
0

안녕하세요 메신저 스레드에 의해 실행되는 메서드에서 .setText 사용하여 textview 값을 설정하려고하지만 대신 TextView에 추가됩니다. 매개 변수 문자열 F는 존재가이 같은 for 루프의 방법으로 전송할 수 있습니다 :TextView setText가 대신 추가됩니다

for (int j = 0; j < 5; j++) { 
     String[] string = array[j].split(":"); 
     String y= string[0]; 
     String x= string[1]; 
     determineSeat(y, something, x); 
    } 
} 

private void determineSeat(String is, String cs, String f) 
{ 
      TextView txtHand = null; 
    String txt = null; 

    if (iSeat < cSeat) { 
     x = cSeat - iSeat; 

     if (x == 1) { 
      txtHand = (TextView) findViewById(R.id.txtHand8); 
      txt = txtHand.getText().toString(); 
      txtHand.setText(""); 
      txtHand.setText(txt + ":" + f); 
     } 
} 

XML :

<TextView 
    android:id="@+id/txtHand1" 
    android:layout_width="73dp" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/textView1" 
    android:layout_centerHorizontal="true" 
    android:text=" " /> 

내가 내가되는 대신 텍스트 뷰에 뭔가를 넣어 그것을 매번 삭제하려면 아무도 그 문제가 뭔지 아는가?

답변

2

위한 것이며, CS. "txt"은 이미 텍스트 뷰에 있던 내용으로 정의됩니다. 메소드가 호출 될 때마다 "f"으로 설정하고 싶다면 "txtHand.setText(f);" 현재 텍스트 뷰에있는 모든 것을 가져 와서 콜론을 추가하도록 요청할 것입니다. "f."

+0

Yosem이 게시 된 후 글쓰기가 시작되었습니다. 그래서 나는 그의 지위를 보지 못했다. 기본적으로, 그는 말했습니다. – gmaster

+0

내 의견으로는, 당신의 대답은 훨씬 더 명확하고 문제를 해결하는 방법을 더 잘 설명합니다. 내 표를 얻었 어. –

+0

Thx, 대답은 사실 내가 지금 txt 문자열로 무엇을 하려는지 잊어 버렸습니다. 너무 오랫동안 바빠서 내가 더 이상 잘못하고있는 것이 미안하다는 것을 알지 못했습니다. 이 주제는 답변되었습니다. – Vern

1

난 당신이 VAR에게 현재 텍스트 할당하는 생각이 라인 :f에 붙이는 다음

txt = txtHand.getText().toString(); 

을 그리고

txtHand.setText(txt + ":" + f); 
0

나는 새 텍스트 상자 객체를 초기화하기 때문에이 생각 루프 내부에서 evrytime을 실행 한 다음 내용을 새 루프에 추가합니다. 루프 밖에서 텍스트 상자를 선언하고 초기화해야합니다.

TextView txtHand = (TextView) findViewById(R.id.txtHand8); 

for (int j = 0; j < 5; j++) { 
     String[] string = array[j].split(":"); 
     String y= string[0]; 
     String x= string[1]; 
     determineSeat(y, something, x); 
    } 
} 

private void determineSeat(String is, String cs, String f) 
{ 
    String txt = null; 

    if (iSeat < cSeat) { 
     x = cSeat - iSeat; 

     if (x == 1) { 
      txtHand.setText(":" + f); 
     } 
} 

는 어떤 문자열을 것은 당신이 "txt + ":" + f"로 설정되어

관련 문제