Android imeOptions and auto-click login

I have a typical login screen. I was able to use imeOptions to allow the user a β€œtab” from one field to another, and in the last field (password) I have actionDone - it just closes the soft keyboard. Ideally, I like to automatically click "Login." Is there anything for this?

+4
source share
1 answer
public class Main extends Activity { private final static String USERNAME = "user1"; private final static String PASSWORD = "12345678"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.page1); final EditText usernameInput = (EditText) findViewById(R.id.username); EditText passwordInput = (EditText) findViewById(R.id.password); passwordInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable input) { if (USERNAME.equals(usernameInput.getText().toString()) && PASSWORD.equals(input.toString())) { setContentView(R.layout.page2); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); } } 

page1.xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="username:" /> <EditText android:id="@+id/username" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="password:" /> <EditText android:id="@+id/password" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> 

page2.xml

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Login successful." /> </LinearLayout> 
+1
source

All Articles