开发者

Clearing EditText when onResume()

I am creating an app where if the user leaves the app by any means and returns, I would like all the EditText fields cleared.

I have created some code that I thought would work which is:

@Override
public void onResume {
    super.onResume;
    (E开发者_JS百科ditText)findViewById(R.id.NumberEntry).setText("");
    (EditText)findViewById(R.in.NameEntry).setText("");
}

However when I click on the Help menu (done through onMenuItemSelected()) and ask for help the app gets the help file and gets it ready to draw but then crashes. I can't figure out why. Any advice would be appreciated.

Or if anyone has another method that will work.

Thanks


I'm not familiar with R.in, did you mean to type R.id.NameEntry?

@Override
public void onResume {
    super.onResume;
    (EditText)findViewById(R.id.NumberEntry).setText("");
    (EditText)findViewById(R.id.NameEntry).setText("");
}


In addition to the typo theisenp said, you may need to cast the views to EditText's before calling setText --

@Override
public void onResume {
    super.onResume;
    ((EditText)findViewById(R.id.NumberEntry)).setText("");
    ((EditText)findViewById(R.id.NameEntry)).setText("");
}

Notice the extra set of parenthesis.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜