Java how to get input for EditText from toggleSoftInput - java

I created EditText by drawing it on canvas so I have problem on making the keyboard appear when clicked and to make the EditText receive input. After some searching, I found out that I can use InputMethodManager to make the keyboard appear to give inputs for EditText.
Unfortunately, EditText does not receive any character inputs from anything pressed on the soft keyboard.
And I need to use imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); because when I used imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);the soft keyboard did not appear at all when EditText is pressed.
Code:
if((int)event.getX() > 50 && event.getX()<400 && event.getY() > 50 && event.getY() < 200){
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
How to solve this? Any working solution is welcomed. Thanks!

This should work fine.
EditText edit = (EditText) view.findViewById(R.id.passwordtextvalue);
edit.setOnKeyListener(this);
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
edit.requestFocus();
I have this in my app, and its working fine for edit text when I have the soft keyboard

Try this
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

Related

Ime_option is changing automatically

My EditText email_edittext is changing the ime_option from IME_ACTION_DONE to IME_ACTION_NEWLINE newline means the arrow to make new line.
this is my code
email_edittext.requestFocus();
InputMethodManager imm =
(InputMethodManager) getSystemService(SignupActivity.INPUT_METHOD_SERVICE);
imm.showSoftInput(email_edittext, InputMethodManager.SHOW_IMPLICIT);

android soft keyboard not showing on button click [duplicate]

This question already has answers here:
How to close/hide the Android soft keyboard programmatically?
(126 answers)
Closed 7 years ago.
Here is the method on buttonclick but it is not working... i have tried many things but nothing seems to be work
public void open_keyboard(View view)
{
message.msg_l(this, "keyboard clicked");
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
please try this,
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
Try something like this:
InputMethodManager imm = (InputMethodManager)getSystemService(MainActivity.this.INPUT_METHOD_SERVICE);
imm.showSoftInput(mainLayout.getWindowToken(), 0);

How to disable android keyboard in android application [duplicate]

This question already has answers here:
How to close/hide the Android soft keyboard programmatically?
(126 answers)
Closed 8 years ago.
I am creating a calculator app where i have an edittext where the result is shown.I want the data to be entered in the edit text only on clicking the number buttons NOT by the android keyboard.How do i disable the keyboard in my android app.Please help!
Try
editText.setInputType(EditorInfo.TYPE_NULL)
Or
((EditText) findViewById(R.id.LoginNameEditText)).setFocusable(false);
Or
editText.setKeyListener(null);
Try this :
InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
try below code:-
EditText ed = (EditText)findViewById(R.id.editText1);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(ed.getWindowToken(), 0);
ed.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(ed, InputMethodManager.SHOW_IMPLICIT);
}
});
or
Window.SetSoftInputMode (SoftInput.StateAlwaysHidden);
If other situations you can prevent the keyboard showing simply using in the manifest
android:configChanges="orientation|keyboardHidden"
In this way the Android keyboard will not auto-open but is shown only if you click directly the EditText
Just posting an Answer what #yahya already commented.
You should consider using a TextView which is not editable and hence won't make any calls to the Keyboard.
In onClick() event of your button's call the setText(String) method and the apply the text you wish. :)
Ypu can also easily append things as setText(yourTextView.getText().toString + "Your New Text");
Hi Kindly try this: For this you no need any Widgets Context...
InputMethodManager miInputManager = (InputMethodManager) Activity.this
.getSystemService(Context.INPUT_METHOD_SERVICE);
miInputManager.hideSoftInputFromWindow(Activity.this
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
Use
android:windowSoftInputMode="stateHidden"
for <activity> in Android_Manifest.xml

EditText focus can't set

When start run app,of EditText visibbility set "gone" value.After in java visibbility set value visible.
I want at that time open keyboard and focus to be on EditText.I do It ,but don't work
`
editText=(EditText)findViewById(R.id.search_text);
editText.setVisibility(View.VISIBLE);
editText.setFocusable(true);
editText.setSelectAllOnFocus(true);`
try to change it with:
editText.setFocusableInTouchMode(true);
editText.requestFocus();
Also this one:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

How to automatically show soft keyboard on start?

I have an activity that only has a EditText. I want the soft keyboard to show up automatically. How can I do this?
You can use this onResume:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(((EditText) findViewById(R.id.your_view)),InputMethodManager.SHOW_FORCED);
I suggest that you check if there is a Hardware keyboard before you force the keyboard to appear.
To hide:
((InputMethodManager) YourActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(findViewById(R.id.YOUR_VIEW).getWindowToken(), 0);
EDIT:
Try this:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

Categories