2011-10-04 85 views
0

在我的Android程序中,我有一个textview,我想刷新每次点击一个按钮。我有一个数组列表,我想循环显示在UI的顶部。有任何想法吗?如何刷新使用onClick的textview

+0

将'TextView'放置在您的布局中,为Click事件注册'Button',在点击时设置文本并将索引增加1。怎么了?有什么问题吗? – Knickedi

回答

1

不知道你的活动的具体细节,这是一个非常简单的做你想做的事情的方法。不要忘记将一些Date项添加到数组列表中。

public class MyActivity extends Activity { 
    int mIndex = 0; 
    ArrayList<Date> dates; 

    protected void onCreate(Bundle icicle) { 
     super.onCreate(icicle); 

     setContentView(R.layout.content_layout_id); 

     dates = new ArrayList<Date>(); 

     final Button button = (Button) findViewById(R.id.button_id); 
     button.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       TextView t = (TextView) findViewById(R.id.textview_id); 
       if (mIndex >= dates.size()) { 
        mIndex = 0; 
       } 
       if (dates.size() != 0) { 
        t.setText(dates.get(mIndex++).toLocaleString()); 
       } 
      } 
     }); 
    } 
} 
0

如果我正确理解你的问题,不需要特别处理的onClick所有在布局的项目之一可能是拥有一个包含布局顶层的RelativeLayout和透明表面抓住焦点并覆盖屏幕,然后让所有事件处理程序将事件发送到RelativeLayout内容的其余部分,然后更新TextView。