Elshan
Elshan

Reputation: 7693

Android layout design- first element focus issue

When I am designing android layout.The first time all element's focusing order is fine.But after changing focus for first time the order is change [as a bellow image]. (At first it select Number 1 EditText,but now it's goes to select Number 2 EditText),How it's happen ?(below image shown that change).

enter image description here

In Windows there have GUI option to set tab order,but how to set first focus element in android design time?

Upvotes: 1

Views: 1161

Answers (4)

Jay Agravat
Jay Agravat

Reputation: 21

Set <requestFocus/> in first edit text only :

<EditText
    android:id="@+id/edtText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <requestFocus /> 
</EditText>

Upvotes: 0

Elshan
Elshan

Reputation: 7693

I'll removed <requestFocus /> in EditText2 and set it back to relevant element. But I don't know how it's happen automatically :(

Upvotes: 0

Rajesh Mikkilineni
Rajesh Mikkilineni

Reputation: 844

RequestFocus:

in Program

      edittext1.requestFocus();

in XML file

<EditText>
<requestFocus />
 </EditText>

Ref <requestFocus> Any element representing a View object can include this empty element, which gives its parent initial focus on the screen. You can have only one of these elements per file.

Upvotes: 1

jaimin
jaimin

Reputation: 563

if you want to set focus to EditText in your way(in your sequence) then use this code

android:nextFocusDown="@+id/id_of_next_EditText"

in this way you can set who will get the nest focus on pressing enter(return) key and use <requestFocus> in EditText where you want focus when layout is dislayed

Upvotes: 2

Related Questions