Android keyboard enter button to keep keyboard visible - android

I'd like for my enter key to complete an action without hiding the keyboard afterwards. Currently every time I enter something and press the enter button the EditText input is cleared to accept the next input, but as the keyboard disappears I have to click the EditText again so that the keyboard would appear again...
Right now this is on my layout:
<EditText
android:id="#+id/etCommand"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/commandHint"
android:inputType="textNoSuggestions"
android:imeOptions="actionSend" >
</EditText>
And the code:
etCommand = (EditText) findViewById(R.id.etCommand);
etCommand.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendCommand();
}
return false;
}
});
EDIT
As swayam suggested I had to return true inside onEditorAction so that the OS would think the action was handled and leave it alone.

Have a go at this code snippet :
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

Add the KeyListener for EditText for Enter key press and after the task completed requestfocus on edittext again would be solution

Related

How to hide softkeyboard in multiline edittext?

I am making small application. I use EditText to summarize all data. It shows a few times, every time has own line. User is able to write short note next to time.
I have issue with soft keyboard. I would like it to have "ok" instead of enter. I mean, it shoul not do extra line. On enter, keyboard should close.
For now, I have something like this:
EtNotes.setOnKeyListener(new View.OnKeyListener()
{
#Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
}
return false;
}
});
It closes keyboard, but it does extra line and that is the problem.
I have already tried to put:
android:imeOptions="actionDone"
in my layout xml file. Unfortunately it also didn't worked.
To sum up, I would like my keyboard don't do extra line and closes after enter button.
You have to return true in the branch where you handled the key input

Kindle Fire Keyboard Buttons

I have an EditText field in my app:
<EditText
android:id="#+id/task_buy_edit_mass_editText1"
android:minWidth="100dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:imeOptions="actionDone" >
</EditText>
The problem is that on my Kindle Fire, the keyboard that appears when the user wants to edit the EditText has no Done button, just a button that hides the soft keyboard
That wouldn't be a problem if I could intercept the 'hide keyboard' button that I highlighted on the above screenshot. However, it doesn't seem to trigger the OnEditorActionListener I've attached to the EditText, so I'm a bit stuck what to do aside from having my own 'Done' button in my actual layout to take focus away from the EditText, hide the keyboard and make any changes that result from the number being changed
Is there a way to intercept the 'hide keyboard' button, or is there some alternative solution?
Incidentally, I have a regular EditText view elsewhere in my app that has no imeOptions nor specifies inputType and that does have a Return key
Here's the rest of the code for reference:
editText.setOnEditorActionListener(new OnEditorActionListener(){
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE || actionId==EditorInfo.IME_ACTION_NEXT || actionId==EditorInfo.IME_NULL || event.getKeyCode()==KeyEvent.FLAG_EDITOR_ACTION || event.getKeyCode()==KeyEvent.KEYCODE_ENTER){
closeKeyboard(v, done_button);
return true;
}
return false;
}});
// set done button for keyboards without correct IME options
final EditText finalEditText = editText;
editText.setOnTouchListener(new OnTouchListener(){
#Override
public boolean onTouch(View v, MotionEvent event) {
done_button.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
closeKeyboard(finalEditText, v);
}});
done_button.setVisibility(View.VISIBLE);
return false;
}
});
.
private void closeKeyboard(TextView v, View buttonv){
demand.setAmount(Double.parseDouble((v.getText().toString()))); // update the game
// close keyboard
InputMethodManager inputManager = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
v.clearFocus();
buttonv.setVisibility(View.GONE);
}
android:inputType="textMultiLine" and android:singleLine="true" as #James Wald indicated works.
EDIT:
Doing the above will make it the EditText multi line. Instead android:imeOptions="actionGo" worked for my purposes on all devices (AFAIK).

How to add a Button on top of an Android keyboard

Hi guys i was assigned a task in my project,there i need to add a Done button on the top of Android keyboard.In my screen i have an EditText,whenever i click on the EditText it should open a keyboard along with the "Done" Button on the top of an Android keyboard.So that i can attach a Listener to that button to perform my task.Any Suggestions.
Thanks&Regards,
E.N.Krishna.
If you need the keyboard to display the Done button, you need to define this in your EditText
<EditText android:text="EditText" android:layout_width="fill_parent"
android:id="#+id/editText1" android:layout_height="wrap_content"
android:imeOptions="actionDone"/>
You can then catch when the user presses the Done button by using OnEditorActionListener
class DoneOnEditorActionListener implements OnEditorActionListener {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
return true;
}
return false;
}
}
Your answer could be found if you read this.
Namely the concept of IME action.

Accept number and letter input from SIP when android:inputType of EditText View set to "numberDecimal"

When a View loaded, I want to force SIP to open and show Keyboard with numbers. Also, I want a editText view accepts Letter and Number input from SIP
XML
<EditText android:id="#+id/search_bus_by_num_keyword"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:lines="1" android:layout_weight="1"
android:inputType="numberDecimal"
/>
Code
editTextSearchKeyword = (EditText) context.findViewById(R.id.search_bus_by_num_keyword);
editTextSearchKeyword.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
context.hideSIP(editTextSearchKeyword);
searchRoute();
return true;
}
return false;
}
});
editTextSearchKeyword.setText(searchKeyword);
editTextSearchKeyword.requestFocus();
InputMethodManager mgr = (InputMethodManager) context.getSystemService(context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editTextSearchKeyword, InputMethodManager.SHOW_FORCED);
When the View loaded:
http://pwong.name/sip_01.png
When I change the SIP from Number to Letter:
http://pwong.name/sip_02.png , I cannot enter Letter to the editText view.
Is it possible to enter both of number and letter for a editText if I set android:inputType="numberDecimal" to it? Is it possible to change android:inputType at run time?
See this question about how to change the InputType in code. See this link for the EditText input types. As far as your requirements of "I want to force SIP to open and show Keyboard with numbers. Also, I want a editText view accepts Letter and Number input from SIP" - I do not understand. I do not think you can have multiple modes of input for an EditText.
try this code
android:inputType="textVisiblePassword"

After type in EditText, how to make keyboard disappear

From the android tutorial :
pass_text.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
return true;
}
return false;
}
});
}
when click at EditText, it has a keyboard appear on the frame. I want to know after Enter.
How to make keyboard out from frame except click Back.
Thank you
Try the following
For Activity:
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(curEditText.getWindowToken(), 0);
In case of Fragment :
InputMethodManager mgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
give the EditText box you have the attribute android:imeOptions="actionDone"
this will change the Enter button to a Done button that will close the keyboard.
A working approach to get rid of the soft keyboard is to disable and then enable the TextEdit field in the Return-key event, button-press event or whatever. For example:
....
pass_text.setEnabled(false);
pass_text.setEnabled(true);
....
I think we can simply add this attribute to our EditText:
android:inputType="text"
This will automatically force the text to be on a single line and therefore when we click Enter, the keyboard disappears.

Categories

Resources