Reputation: 743
My java class file looks like
public class SignIn extends Activity {
/*** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.signin);
}
/***Enter key event in phone********************************/
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_ENTER:
Intent intent = new Intent(SignIn.this, List_Of_Songs.class);
startActivity(intent);
break;
default:
return false;
}
return true;
}
}
and xml
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/signinemailtxt"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Email" android:textSize="20dp" android:layout_marginTop="65dp"
android:layout_marginLeft="25dp" android:paddingRight="50dp" android:textColor="#000000"/>
<EditText android:id="@+id/signinemailid" android:hint="[email protected]"
android:layout_height="28dp" android:layout_width="170dp"
android:layout_toRightOf="@+id/signinemailtxt"
android:layout_marginTop="65dp"
android:background="#ffffff" android:layout_below="@+id/signinlayout" />
<TextView android:id="@+id/signinpasswordtxt"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Password" android:textSize="20dp"
android:layout_marginTop="20dp" android:layout_marginLeft="25dp"
android:layout_below="@+id/signinemailtxt" android:paddingRight="15dp" android:textColor="#000000" />
<EditText android:id="@+id/signinpassword" android:hint="password"
android:layout_height="28dp" android:layout_width="170dp"
android:layout_toRightOf="@+id/signinpasswordtxt"
android:layout_marginTop="20dp"
android:background="#ffffff" android:layout_below="@+id/signinemailid" />
Now when i press enterkey in phone it doesnt go to the intent..the focus stays up with edittext passsword its self...what to do?
Upvotes: 0
Views: 3970
Reputation: 13
This worked for me once I removed android:imeOptions="actionDone"
from my xml file.
Upvotes: 0
Reputation: 25534
Adding following lines in your java code:
1) Create an object of your edit text:
EditText editText = (EditText) findViewById(R.id.signinpassword);
2) Add a onKeyListener to it:
editText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_ENTER:
Intent intent = new Intent(SignIn.this, List_Of_Songs.class);
startActivity(intent);
break;
default:
return false;
}
return true;
}
});
Upvotes: 2
Reputation: 833
this happens because the onkey method is called when the usr hits the physical key u should overide the keys present in the ime Option ie the softkeyboard
Upvotes: 0