I have a edit text view and button right side to it. When I click the button edittext has to get focus and keyboard has to appear. I programmitically
tried following.
name_text = (EditText)findViewById(R.id.name_text);
name_edit = (ImageView)findViewById(R.id.name_edit_icon);
name_text.setFocusable(false);
name_edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
name_text.setFocusable(true);
//name_text.setEnabled(true);
}
});
I tried all possiblities, none is worked for me. Please help me. Thanks.
Write this code inside the click event to TOGGLE the keyboard:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Related
I have an EditText and an ImageButton (in different ViewGroups) on a single page.
If the EditText is focused, I dont want to unfocus the EditText when I click on the ImageButton.
I tried setting imageButton.setFocusable(false);
It didn't work.
If I long-press on the imageButton the EditText does not lose focus.
EDIT:
I don't want the edittext to lose the focus, not even for some milisecs.
I have a layout that is depending on the "isFocused" property on the EditText.
If you try this?
imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
editText.requestFocus();
}
});
Try this code:
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
I have-
EditText &
Button
How can I open a soft keyboard when one selects the edittext view, the user can write anything and it should display in the edittext.
I used the below code but the keyboard doesn't come up-
EditText edit= (EditText) findViewById(R.id.list);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edit, InputMethodManager.SHOW_IMPLICIT);
Any idea how I can open the keyboard and close it again by using back button?
This is my function to open the keyboard :
protected void showKeyBoard(final View v){
v.post(new Runnable() {
public void run() {
v.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
}
});
}
Make sure
android:windowSoftInputMode="stateAlwaysVisible" in manifest File.
and
edittext.requestFocus();
my case is: I have one EditText field that is with disabled focus.
Beside EditText field I has two buttons for Input methods. So I want when click first button: to open soft keybord and edit text in EditText field. I try many ways with:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
and doesn't work for me. Only way to open soft keyboard is:
toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
but there is no way to edit info from EditText field.
May you suggest me how to open keyboard and edit text for some EditText when click button.
Thanks a lot!
Edited:
So, EditText is not focusable be default. When I click Keyboard button - should be focusable, then show me soft keyboard to enter text and appear in EditText. Other method to insert is A-B-C button which not required keyboard. It will be something like Morse code input - touch and hold A-B-C button :) I'll try suggested example to implement in my case. Thank you guys :)
Thanks guys for your help :) I used all suggestions that you gave me, searched and tested a lot of other scripts and finally my code is working :)
Here is my final code:
InputEditText = (EditText) findViewById(R.id.InputText);
public void InputData() {
/* Keyboard Button Action */
KeyboardButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "On Keyboard Button click event!");
InputEditText.requestFocus();
InputEditText.setFocusableInTouchMode(true);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(InputEditText, InputMethodManager.SHOW_FORCED);
}
});
}
It may be useful for someone :)
Thank you!
The design you've described isn't recommended. You're violating the focusable attribute's purpose which is not to control whether the user can alter the text in a EditText component.
If you plan to provide an alternative input method because the use case seems to require this (e.g. you allow only a certain set of symbols in the editable text field) then you should probably disable text editing altogether for the time the user isn't allowed to change the value of the field.
Declare your editable field:
<EditText
android:id="#+id/edit_text_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
notice that its focusable attribute is left with the default value. That's ok, we'll handle that later. Declare a button which will start editing process:
<Button
android:id="#+id/button_show_ime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start editing" />
Now, in your Activity declare:
private EditText editText2;
private KeyListener originalKeyListener;
private Button buttonShowIme;
And in onCreate() do this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ime_activity);
// Find out our editable field.
editText2 = (EditText)findViewById(R.id.edit_text_2);
// Save its key listener which makes it editable.
originalKeyListener = editText2.getKeyListener();
// Set it to null - this will make the field non-editable
editText2.setKeyListener(null);
// Find the button which will start editing process.
buttonShowIme = (Button)findViewById(R.id.button_show_ime);
// Attach an on-click listener.
buttonShowIme.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Restore key listener - this will make the field editable again.
editText2.setKeyListener(originalKeyListener);
// Focus the field.
editText2.requestFocus();
// Show soft keyboard for the user to enter the value.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText2, InputMethodManager.SHOW_IMPLICIT);
}
});
// We also want to disable editing when the user exits the field.
// This will make the button the only non-programmatic way of editing it.
editText2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
// If it loses focus...
if (!hasFocus) {
// Hide soft keyboard.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText2.getWindowToken(), 0);
// Make it non-editable again.
editText2.setKeyListener(null);
}
}
});
}
I hope the code with all the comments is self-explanatory. Tested on APIs 8 and 17.
Try this :
final EditText myedit2 = (EditText) findViewById(R.id.myEditText2);
Button btsmall = (Button) findViewById(R.id.BtSmall);
btsmall.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
myedit2.requestFocus();
}
});
I Have Work this code for open a keybord when button click.
Like .
btn1 = (Button) findViewById(R.id.btn1);
edt1 = (EditText) findViewById(R.id.edt1);
btn1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
edt1.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(edt1, InputMethodManager.SHOW_IMPLICIT);
}
});
its completed work.
LinearLayout ll_about_me =(LinearLayout) view.findViewById(R.id.ll_about_me);
ll_about_me.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
mEtEmpAboutYou.requestFocus();
mEtEmpAboutYou.setFocusableInTouchMode(true);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEtEmpAboutYou, InputMethodManager.SHOW_FORCED);
return true;
}
});
For those that uses fragments you can use InputMethodManager that way:
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
}
Full Code:
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
}
}
});
I hope this help
EditText txt_categorie = findViewById(R.id.txt_categorie);
txt_categorie.requestFocus();
anyone know if android is possible to hide the keyboard of a inputText after pressing a button?
in my application the keyboard is always present after a consultation which is uncomfortable for the user
yes:
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
}
});
May I know is it possible to invoke android softkeyboard or Softkeyboard sample provided in the Androidsdk sample by button click? As of now I could invoke the softkeyboard only on edit view control's focus.
As per the below suggestion I did the following modification, but still didnt worked:
here is my code.. i got error on using getContentView() so I used "v".
private OnClickListener mKeypadbtnListener = new OnClickListener() {
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInputFromInputMethod(v.getWindowToken(), 0);
}
You should try imm.showSoftInput(view, 0); instead of v.getwindowToken(). I think this will help you.
You can display the soft keyboard issuing the following:
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(getContentView().getWindowToken(), 0);