【问题标题】:Textview onclick() in widget android小部件android中的Textview onclick()
【发布时间】:2013-07-03 08:02:47
【问题描述】:

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

【问题讨论】:

  • 你能发布一些代码吗?究竟是什么不起作用。这个问题提供了一些关于如何在小部件stackoverflow.com/questions/9851000/… 中使用 onClick() 的信息
  • 展示一些努力也许有人可以帮忙,我想没有人会喜欢做你的功课!
  • 问题出在哪里??

标签: android onclick widget textview


【解决方案1】:

如果我理解您要正确执行的操作,请尝试以下操作:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-18
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 2013-01-12
    • 1970-01-01
    相关资源
    最近更新 更多