-2

我们在数组列表中存储了一些文本。我们想在单个文本视图中显示它,当我单击文本视图时,arraylist 中的下一个值(文本)应该在小部件中更新。

4

1 回答 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 回答