I have 3 edittext in my activity. The first edittext will be setFocusable(false) if the edittext length is not equal to 0(value on 1st edittext will be from sqlite). So when I start the activity, the focus will be on the second edittext. If I click on the 1st edittext, a dialog will prompt with YES and NO button. If I click yes, it will focus on the 1st edittext and I can edit the value. But when I press the enter key on the phone keyboard, it will not direct me to the second edittext. It will stay on the 1st edittext. The only way I can go to the second edittext is to press the back button and click on the 2nd edittext. Any idea how can I fix this problem?
Here’s my code for the edittext:
if (txtBudgetText.getText().toString().length() != 0) {
txtBudgetText.setFocusable(false);
this.txtBudgetText = (EditText) findViewById(R.id.txtBudget);
this.txtBudgetText.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// custom dialog
if ((txtBudgetText.getText().toString().length() != 0) && (txtBudgetText.isFocused()==false) ) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.edit_budget);
dialog.setTitle("Confirmation");
// set the custom dialog components - text, image and
// button
TextView text = (TextView) dialog
.findViewById(R.id.text);
text.setText("Are you sure you want to edit your budget?");
ImageView image = (ImageView) dialog
.findViewById(R.id.image);
image.setImageResource(R.drawable.warning);
Button dialogYESButton = (Button) dialog
.findViewById(R.id.dialogButtonYes);
// if button is clicked, close the custom dialog
dialogYESButton
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText txtBudgetText = (EditText) findViewById(R.id.txtBudget);
txtBudgetText.setFocusableInTouchMode(true);
txtBudgetText.setFocusable(true);
txtBudgetText.requestFocus();
//txtBudgetText.setText("");
dialog.dismiss();
}
});
Button dialogNOButton = (Button) dialog
.findViewById(R.id.dialogButtonNo);
// if button is clicked, close the custom dialog
dialogNOButton
.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
});
}
add
txtBudgetText.setImeOptions(EditorInfo. IME_ACTION_NEXT);after you calledfindViewByIdor set it in your layout.xml by settingandroid:imeOptions="actionNext"in your EditText layout declaration.