Android TextView文本未更新,但颜色更新

时间:2013-07-26 10:40:05

标签: android textview

在按钮上单击我想设置textview的值为零。但是textview没有更新但我可以设置文本颜色。我尝试了一些解决方案,如postdelayed和runOnUIThread但没有更改。我使用了Tab在我的应用程序中,当我转到另一个选项卡并再次回到此活动时出现问题。请帮助我。谢谢。

public void Delete(View view) {

    time.setTextColor(Color.GREEN);
    time.setText("0");
    time.setTextColor(Color.BLUE);

}

 <ImageButton
                    android:id="@+id/delete_sound"
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:layout_marginLeft="15dp"
                    android:background="@android:color/transparent"
                    android:clickable="true"
                    android:contentDescription="@string/dummyString"
                    android:onClick="Delete" />

2 个答案:

答案 0 :(得分:0)

尝试重新初始化 Delete()

public void Delete(View view) {
        TextView time=(TextView)findViewById(R.id.your_text_view_id);
        time.setText("0");
    }

onCreate()

中修改或尝试
ImageButton ib = (ImageButton) findViewById(R.id.delete_sound);
        ib.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Delete(v);
            }
        });

答案 1 :(得分:0)

试试这个。它对我来说很好

    (findViewById(R.id.btnchange)).setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v)
        {
            TextView time = (TextView)findViewById(R.id.Your_Textview_ID);
            time.setTextColor(Color.GREEN);
            time.setText("0");
            time.setTextColor(Color.BLUE);
        }
    });