Though i have asked the question before but dint get any proper answer. I have an EditText when edit text is focused android virtual keyboard pops up, i have added Done button to the keyboard using ime option from property window. Now i want to perform some action by pressing the Done button. How to do this? Please any body help.
you an do it by firest finding reference of edittext and than set belows code for ur edittext:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();//do here your stuff f
return true;
}
return false;
}
});
here i have taken editText name which is ref. editextbox which u added and you have to add actionId==type of ime options which u have setted
Related
I am searching for a way to customize (or handle) the 'Enter' of the virtual keyboard when some app user is giving some input in an Android app, for example, when he is pressing "Enter" in an Android app (in some EditText) or when he has completed giving his input, then at that point (or before) can I customize the 'Enter' of the virtual keyboard (like in some apps' virtual keyboard, it is "Done") to text like "Go" etc. Also, if something like some (other) action could also be possibly performed when that virtual keyboard button (like Enter) is being clicked or pressed. Any kind of help would be greatly appreciated.
You can set different imeOptions like actionDone and actionGo reference link
imeOptions can setted like this in editText
android:imeOptions="actionDone"
to customize these imeActions firstly you can change imeOptions label like this
android:imeActionLabel="#string/anyString"
You have to implements OnEditorActionListener interface and set it to your EditText
editText.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Toast.makeText(getApplicationContext(), "Your changes have been saved", Toast.LENGTH_SHORT).show();
}
}
});
set ImeOptions
et_input.setImeOptions(EditorInfo.IME_ACTION_DONE);
Editor Action Listener
et_input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
int result = actionId & EditorInfo.IME_MASK_ACTION;
switch (result) {
case EditorInfo.IME_ACTION_DONE:
break;
case EditorInfo.IME_ACTION_NEXT:
//
break;
}
return true;
}
});
Looking at the Android documentation here:
https://developer.android.com/training/keyboard-input/style.html,
specifically:
EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
});
This does not close the keyboard after clicking the send button. It also does not close the keyboard if handled is set to false.
What is the appropriate way to hide the keyboard in this case?
Looking at :-
how to hide keyboard after typing in EditText in android?, there seems to be a multitude of ways. Is this really the way to go in Android?
I've searched a lot of threads and nothing resolved my problem.
How can I go to another field by clicking "next button" on keyboard in that condition?
I've got "FieldValidLayout" with TextViews and "CustomEditText". After next button clicked on keyboard i would like to go to the "CustomEditText" in next "FieldValidLayout".
you can directly add in xml
android:imeOptions="actionNext"
or if you want more functions then
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//add your code
}
I saw many searchboxes in apps that if click the keyboard layout changes into Search button. How to change the android keyboard layout from Enter to Search if an EditText is click? Just like other search boxes. Thanks
add
android:imeOptions="actionSearch"
to your EditText in your layout file.
After that you can manage "search" click event by following code:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
}
});
I have 5 edit texts where user enters his options, I keep first two visible and other 3 visibility gone. If user wants to enter option 3 I make it visible by pressing action next key on keyboard while user finishes typing on option 2. But the problem is it doesnt focus on edit text 3. Now to experiment visibility of edittext 3 from gone to invisible, action next method works well. Is there a way to make input next method work when view's visibility turns gone to visible?
I am using this code to make focus appear on edittext 3 which is not working in case of edittext visibility turning visible from gone. Same code works well in case of edittext visibility turning visible from invisible.
option2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_NEXT){
option3.setVisibility(View.VISIBLE);
option3.requestFocus();
}
return false;
}
});
How to make focus on button3 :
button2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_NEXT) {
button3.setVisibility(View.VISIBLE);
button3.requestFocus();
}
return false;
}
});