问题
I have an EditView
and I have added :
android:imeActionLabel="Go"
This is showing "Go" button in keyboard, but I don't know how to perform an action when user clicks "Go" button.
Is there any solution about this, if yes how can I do it?
回答1:
EditText.OnEditorActionListener
is what you are looking for, the API Documentation can be found here. The action that will be called for the GO button is EditorInfo.IME_ACTION_GO
. I have provided a brief example below.
editText.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId==EditorInfo.IME_ACTION_GO)
{
//Handle go button pressed
}
return false;
}
});
来源:https://stackoverflow.com/questions/18219340/editview-perform-an-action-on-click