1
我做了以下內容,但它沒有工作單擊操作欄中的搜索按鈕後如何觸發操作?
@Override
public boolean onOptionsItemSelected(MenuItem menuItem)
{
startActivity(new Intent(NamesList.this,MainActivity.class));
switch (menuItem.getItemId()) {
case 1:
search = (EditText) menuItem.getActionView();
search.addTextChangedListener(filterTextWatcher);
search.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
String result = search.getText().toString();
Toast.makeText(getApplicationContext(), "the :: " + result, Toast.LENGTH_LONG);
}
return true;
}
感謝您的答案,但即時消息試圖做的是顯示搜索字段的值,一旦搜索按鈕被點擊,如顯示它作爲祝酒 – user1283633
已更新的答案 – Nermeen