onResume()更新的TextView [英] onResume() update TextView

查看:135
本文介绍了onResume()更新的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的主要depotactivity他设置整数值一个TextView,现在我想的时候onResume()被调用该值以得到更新......但是当我加入我的小onResume()code

I have my main depotactivity where he sets integer value to a textview, now I want this value to get updated when onResume() is called... but when I add my little onResume() code

public class DepotActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        DepotDBUtils utils = new DepotDBUtils(this);
        int itemcount = utils.countItems(this);

        TextView tv = (TextView)findViewById(R.id.counter);
        tv.setText(tv.getText()+" "+itemcount);
    }
   String TAG = "DepotActivity";
   String[] itemInfo;
 public void onResume(){
    Log.d("DepotActivity","onResume() gets called");
    DepotDBUtils utils = new DepotDBUtils(this);
    int itemcount = utils.countItems(this);

    TextView tv = (TextView)findViewById(R.id.counter);
    tv.setText(tv.getText()+" "+itemcount);
    } 

到应用程序,我甚至不能启动它,LogCat中得到完全疯了,不记录任何活动超过半秒。任何解决办法?在此先感谢

to the app I can't even start it, and LogCat gets totally crazy and doesn't log any activity for more than half a second. Any solutions? Thanks in advance

推荐答案

我会从增加 super.onResume();

@Override
protected void onResume(){
    super.onResume();
    // The rest
}

我也将删除:

I would also remove that:

    DepotDBUtils utils = new DepotDBUtils(this);
    int itemcount = utils.countItems(this);

    TextView tv = (TextView)findViewById(R.id.counter);
    tv.setText(tv.getText()+" "+itemcount);

的onCreate ,因为每个的onCreate 被调用时, onResume 被称为好。

from onCreate, since every time onCreate is called, onResume is called as well.

这篇关于onResume()更新的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆