onResume() 更新 TextView
我有我的主要仓库活动,他将整数值设置为文本视图,现在我希望在调用 onResume() 时更新该值...但是当我将我的小 onResume() 代码添加
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 变得完全疯狂,超过半秒没有记录任何活动。有什么解决办法吗?提前致谢
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);
}
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先添加
super.onResume();
:我还会
从
onCreate
中删除:,因为每次调用onCreate
时,onResume
也会被调用。I'd start with adding
super.onResume();
:I would also remove that:
from
onCreate
, since every timeonCreate
is called,onResume
is called as well.