0

こんにちは、スレッドによって実行されるメソッドで .setText を使用して textview の値を設定しようとしていますが、代わりに TextView に追加されています。パラメータ文字列 f は、次のように for ループでメソッドに送信されます。

    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=" " />

追加するのではなく、テキストビューに何かを入れるたびにクリアしたいのですが、何が問題なのか知っている人はいますか?

4

3 に答える 3

2

に設定してい"txt + ":" + f"ます。 "txt"すでにテキストビューにあったものとして定義されています。"f"メソッドが呼び出されるたびに設定したい場合"txtHand.setText(f);" は、現状のままで、現在テキストビューにあるものをすべて取得し、コロンと"f."

于 2012-07-31T21:53:20.843 に答える
1

このvarに現在のテキストを割り当てていると思います:

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

そして、:fこの行を先頭に追加します

txtHand.setText(txt + ":"  + f);
于 2012-07-31T21:50:05.807 に答える
0

ループ内で毎回新しいテキストボックスオブジェクトを初期化し、その内容を新しいオブジェクトに追加しているためだと思います。ループの外でテキストボックスを宣言して初期化する必要があります。

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);
        }
}

文字列とcsは何ですか

于 2012-07-31T21:51:07.407 に答える