- Forum posts: 1
Mar 24, 2016, 3:36:38 PM via Website
Mar 24, 2016 3:36:38 PM via Website
MainActivity.java
{
private AutocompleteTextView actv;
A)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item=menu.findItem(R.id.autoCompleteTextView);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
actv.setText("");
//getting Null Pointer Exception here
return false;
}
});
}
B)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id){
case R.id.autocompletetextview:
break;
case R.id.reset_button:
break;
default:
}
return super.onOptionsItemSelected(item);
}
}
1st Question: Am I doing it right to clear text inside autoCompleteTextView by pressing button? If not, rectify it
Another follow-up question,we can also add a listener in onOptionsItemSelected?
So what is OnCreateOptionsMenu vs onOptionsItemSelected?
What should I put inside exactly ?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.