私はint型の値を変更すると、文字列のintは変更されません。

ムハンマドFadliフィルダウス:

私は(ところでハードコード)文字列内のint値を使用するコードを作ってるんだだから、それは動作しますが、私はボタンクリックでint型の値をインクリメントするとき、文字列のintは増分として変更されません。

int indexOfQuestion= 1; 
numberOfQuestion.setText("Question " + indexOfQuestion + " from " + lengthOfQuestion + " :" );
switch(v.getId()):
case R.id.next:
indexOfQuestion = indexOfQuestion+1;

私はボタンをクリックしたときに、私は長い冗長なコードなしで意図したように、numberOfQuestion滞在中indexOfQuestion 1.どのように私はそれを自動的に変更するには?感謝

MatinのGdz:

あなたがint値をインクリメントする前に、あなたがのsetTextので、それは変更されません。あなたが変更を適用したい場合は、インクリメントした後、再度のsetText必要があります。

int indexOfQuestion= 1;

numberOfQuestion.setText("Question " + indexOfQuestion + " from " + lengthOfQuestion + " :" );
switch(v.getId()):
case R.id.next: indexOfQuestion = indexOfQuestion+1;
numberOfQuestion.setText("Question " + indexOfQuestion + " from " + lengthOfQuestion + " :" );

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=120308&siteId=1