EditText handling Enter Key

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

EditText handling Enter Key

Postby John5788 » Sun Nov 08, 2009 5:32 am

anyone have sample code for handling an enter key event in an EditText? right now my box just stretches when Enter is pressed, but I would like it to handle the same event as pressing the send button right next to it.
John5788
Freshman
Freshman
 
Posts: 4
Joined: Fri Oct 09, 2009 6:45 am

Top

Postby Emmanuel7 » Sun Nov 08, 2009 1:45 pm

Not exactly what you are after, but adding this :
android:singleLine="true"
In your textview parameters helps a little :
The text view no longer stretches, and on 'enter', the focus just goes to the next widget ( hopefully the 'ok' button' )


Perhaps you can do a better job with a TextChangedListener, but I've not tried it ( at least not for a final solution )

Hope it helps,
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby John5788 » Mon Nov 09, 2009 12:57 am

how does it determine what the next widget is?
John5788
Freshman
Freshman
 
Posts: 4
Joined: Fri Oct 09, 2009 6:45 am

Postby sandis84 » Mon Nov 09, 2009 10:26 am

try this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 edittext.setOnEditorActionListener(new OnEditorActionListener(){
  2.  
  3.  
  4.  
  5.                         @Override
  6.  
  7.                         public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
  8.  
  9.                                 if(arg1 == EditorInfo.IME_NULL) {
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


The layouts try to determine by themselves what the next view is, most likely the one to the right or below. You can also specify it with xml-attributes "nextFocus...", for example:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:nextFocusDown="@+id/textview1"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
sandis84
Experienced Developer
Experienced Developer
 
Posts: 78
Joined: Fri Aug 07, 2009 3:54 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 10 guests