AutoCompleteTextView enter press - android

In EditText android:nextFocusDown="#+id/fuelfrom" will goes to next field when press done, similarly, how can I make a AutoCompleteTextView goes to next field when pressing enter key...

Use
android:singleLine="true"
it will show focus on next field on pressing enter.
EDIT:
try this one
android:imeOptions="actionNext"

use this.
<EditText android:imeOptions="actionDone"
android:inputType="text"/>
edittext.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((actionId == EditorInfo.IME_ACTION_DONE)) {
Log.i(TAG,"Here you can write the code");
}
return false;
}
});
should return true in the if clause to say you've handled i

Related

What is the keycode for search/next/send button

does anyone know what keycode I have to press for this Send/Search/Next button?
I'm trying to send a chat message and can't find a solution to this one.
Already tried keycode: 66 and 84.
keyboard view
For adding action on click of send/done button of soft keyboard, Need to add setOnEditorActionListener to edittext.
EditText code in xml :
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSend"
android:singleLine="true"/>
In Java class:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
String text = editText.getText().toString();
Log.e(TAG,"text-----"+text);
return true;
}
return false;
}
});
You can add any imeOptions to edittext according to your requirement.
For more info related to EditerInfo check official doc.

OnEditorActionListener with imeOptions actionNext not working

Here is my code:
<android.support.design.widget.TextInputLayout
android:id="#+id/mylayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/some_layout">
<android.support.design.widget.TextInputEditText
android:id="#+id/myid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="#string/some_hint"
android:imeOptions="actionNext"
android:inputType="time"
android:maxLength="#integer/max_input_length"
android:maxLines="1"
android:singleLine="true"
android:textSize="15sp"/>
</android.support.design.widget.TextInputLayout>
and the Java code:
myField = (TextInputEditText) findViewById(R.id.myid);
myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
Log.d(TAG,"next");
//Do something
handled = true;
}
Log.d(TAG,"handled: "+handled);
return handled;
}
});`
Unfortunately when I press the next button on the keyboard nothing happens. The cursor doesn't jump to the next field.
I can't see what I am missing
use android:inputType="text" for your TextInputEditText
try calling view.requestFocus(); in your action .
myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
Log.d(TAG,"next");
//Do something
Log.d(TAG,"handled: "+handled);
view.requestFocus() ; //add focus to next view object
return true; //return true
}
Log.d(TAG,"handled: "+handled);
return false; //add return
}
});
As per doc
IME_ACTION_NEXT
Bits of IME_MASK_ACTION: the action key performs a "next" operation,
taking the user to the next field that will accept text.
So it means it will focus on next focusable object like edittext or auto complete text view. so if no other object can get focus it will not move focus.

Press Enter to change EditText

My problem is that I have a login screen that contains 2 EditText views. When I enter the username and click Enter, it adds more lines, but I want it to change to the EditText password instead. Can someone please help me?
public void onClick(View v){
final TextView user = (TextView)findViewById(R.id.tnome);
final TextView pw = (TextView)findViewById(R.id.tpw);
if (user.getText().toString().equals("") || pw.getText().toString().equals((""))) {
Toast.makeText(MainActivity.this, "Têm de Preencher todos os Campos", Toast.LENGTH_SHORT).show();
user.requestFocus();
}else{
if (user.getText().toString().endsWith(" ")){
user.setText(user.getText().toString().substring(0,user.length()-1));
}
user.setText(user.getText().toString().toLowerCase());
if (user.getText().toString().equals("admin") && pw.getText().toString().equals("admin")){
startActivity(new Intent(MainActivity.this,Home.class));
user.setText("");
pw.setText("");
}
user.setOnKeyListener(new View.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 Enter key press
user.clearFocus();
pw.requestFocus();
return true;
}
return false;
}
});
pw.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
// check for username - password correctness here
return true;
}
return false;
}
});
}
}
Using the android:inputType="text" (or another value) to limit input text to one line.
Usually, when input controls are laid out in a layout file (resx), pressing ENTER will cause focus to go to the next field. You shouldn't need any custom handling code to have this work (i.e. you shouldn't need code on the username field to make ENTER set focus to the password field).
You can use the <requestFocus /> tag to force focus to a field when the page is loaded.
<EditText
android:id="#+id/etUserName"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:focusable="true"
>
<requestFocus />
</EditText>
<EditText
android:id="#+id/etPassword"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:cursorVisible="true"
android:hint="Password"
/>
The most likely reason that the wire-up of the listener isn't working is that the code is only run when a button is clicked (it's in an onClick function). Perform the wire-up for the password (pw) field during page initialization instead - onFinishInflate() is a good spot.
You might, however want to wire-up a key listener to make an ENTER press in the password field submit the data (or do validation).

Soft keyboard, edittext setImeActionLabel() isn't working?

I am using this code in XML file for edit text.
<EditText
android:id="#+id/et_login_password"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_login_views_height"
android:layout_below="#+id/et_login_email"
android:ems="10"
android:hint="password"
android:inputType="textPassword"
android:text="Vidcode2015"
android:textColor="#color/primary_dark"
android:textColorHint="#android:color/tertiary_text_light"
android:textSize="#dimen/fragment_login_views_text_size" />
And in java file i am setting edittext properties.
et_password.setImeActionLabel("Login",EditorInfo.IME_ACTION_SEND );
et_password.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
performLogin(et_user.getText().toString(), et_password.getText().toString());
handled = true;
}
return handled;
}
});
Android only provide with specific labels through imeOptions on edit text to set on softkeyboard button, like done or send e.t.c. User cannot set his/her own label like login or abc e.t.c

How to display "search" as text instead of Serach icon on android soft keyboard

How to replace the search icon with text "Search" on soft keyboard.
<EditText
android:imeOptions="actionSearch" />
Instead of using imeOptions use the following :-
<EditText android:imeOptions="actionSearch"
android:inputType="text"/>
For handling click listener do as follows :
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;
} });
Answer taken from this stackoverflow question.
Try to set
android:imeActionLabel in XML or
in java code with .setImeActionLabel()
editText.setImeActionLabel(getString(R.string.xxx), EditorInfo.IME_ACTION_SEARCH);

Categories

Resources