我有主要的仓库管理人员,他在其中将整数值设置为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变得非常疯狂,并且没有记录任何活动超过半秒钟。有什么办法吗?提前致谢
我将从添加super.onResume();:
super.onResume();
@Override protected void onResume(){ super.onResume(); // The rest }
我还将删除该内容:
DepotDBUtils utils = new DepotDBUtils(this); int itemcount = utils.countItems(this); TextView tv = (TextView)findViewById(R.id.counter); tv.setText(tv.getText()+" "+itemcount);
from onCreate,因为每次都onCreate被调用,所以onResume也被调用。
onCreate
onResume