How to place the cursor in a specific EditText field?

My XML contains Five EditText and One Button. Now my cursor points to the first EditText . How can I click a button to automatically place the cursor in the Third EditText .

Thanks!

+8
android
source share
6 answers

put on your onClick() button ..

 thirdEditText.requestFocus(); 

Something like,

 button.setOnClickListener(new OnClickListener() { public void onClick(View v) { thirdEditText.requestFocus(); } }); 
+11
source share

editText3.requestFocus ();

Add a button method to onClick.

+2
source share

Use the requestFocus() method to get focus.

Or put <requestFocus / "> in your XML layout.

+1
source share

this is the code:

 btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { edittext.setFocusableInTouchMode(true); edittext.requestFocus(); } }); 
+1
source share

try

 EditText editText = (EditText) findViewById(R.id.textId); editText.requestFocus(); 
0
source share

just add the <requestFocus/> to EditText as:

 <EditText android:id="@+id/editText" android:layout_width="320dp" android:layout_height="wrap_content" android:layout_below="@id/label" android:inputType="numberDecimal" android:textSize="25dp" > <requestFocus /> </EditText> 
0
source share

All Articles