KeyCode_Enter to next edittext

Put your problem here if it does not fit any of the other categories.

KeyCode_Enter to next edittext

Postby soclose » Fri Jun 11, 2010 4:12 am

Hi,

In edittext, after typing 'Enter' key, system make a new line inside it. I'd like to focus on next edittext, no new line. how to code? my code in xml is below

Code: Select all
    <EditText
    android:id="@+id/txtNPCode"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:layout_alignLeft="@+id/lblNPCode"
    android:layout_below="@+id/lblNPCode"
    android:layout_centerHorizontal="true"
/>
<EditText
    android:id="@+id/txtCNPCode"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:layout_alignLeft="@+id/lblCNPCode"
    android:layout_below="@+id/lblCNPCode"
    android:layout_centerHorizontal="true"
    /> 


I also caputer key code in setOnKeyListener

Code: Select all
       
tCNPCode.setOnKeyListener(new OnKeyListener() {

public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if(keyCode == 66) { Toast.makeText(S_PCode.this, "Enter Key",
Toast.LENGTH_LONG).show();
//tNPCode.setFocusable(true);

}
return false;   

} });
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Top

Re: KeyCode_Enter to next edittext

Postby anarche » Fri Jun 11, 2010 4:32 am

Yep, you are on the right track with the OnKey listener.

get the id of the next EditText and focus.
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Re: KeyCode_Enter to next edittext

Postby soclose » Fri Jun 11, 2010 4:38 am

I use requestFocus. It worked.

Code: Select all
    tCNPCode.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if(keyCode == 66) {
            txtCNPCode.requestFocus();
            return true;
        }
        else return false;
    }
});
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Re: KeyCode_Enter to next edittext

Postby soclose » Fri Jun 11, 2010 8:45 am

button focus?
soclose
Experienced Developer
Experienced Developer
 
Posts: 80
Joined: Sun Apr 25, 2010 8:38 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 9 guests