配列リストにテキストを保存しました。それを単一のテキストビューに表示したいのですが、テキストビューをクリックすると、配列リストの次の値(テキスト)がウィジェットで更新されます。
1 に答える
0
あなたが正しくやろうとしていることを理解したら、これを試してください:
public class MyActivity extends Activity {
ArrayList<String> values = new ArrayList<String>();
TextView myText;
private int index;
protected void onCreate(Bundle saved) {
super.onCreate(saved);
setContentView(R.layout.content_layout_id);
index = 0;
//example values:
values.add("foo");
values.add("bar");
values.add("another value");
myText = (TextView) findViewById(R.id.myTextId);
//show the first value on myText
myText.setText(values.get(index));
myText.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Show next value in our text view:
myText.setText(values.get(++index));
//be sure to consider the ArrayList.size() so you won't try to present the 6th value in a 5 values ArrayList.
//but this depends on your implementation.
}
});
}
}
于 2013-07-03T08:28:01.003 に答える