onResume () обновляет TextView - PullRequest
0 голосов
/ 31 июля 2011

У меня есть моя основная способность, где он устанавливает целочисленное значение для 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 полностью сходит с ума и не регистрирует какую-либо активность больше половины секунды.Любые решения?Заранее спасибо

1 Ответ

2 голосов
/ 31 июля 2011

Я бы начал с добавления 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);

из onCreate, поскольку каждый раз вызывается onCreate, onResume также называется.

...