Dev
Dev

Reputation: 505

Focus on the first edtitext in android

I have four edittexts the problem is when i start activity the focus will be on the last edittext , how can i make the focus on the first edittext using xml ? Thanks

Upvotes: 6

Views: 8313

Answers (4)

pmoore
pmoore

Reputation: 11

In Android Studio 2.3.3, you can click on the focusedByDefault attribute in the Properties panel on the EditText you want the focus on first.

Upvotes: 1

francadaval
francadaval

Reputation: 2481

You can also add a <requestFocus/> tab in the activity xml.

Upvotes: 5

Mudassir
Mudassir

Reputation: 13174

You can use the requestFocus element.

Upvotes: 5

onCreate(); of Activity

EditText firsteditText=(EditText)findViewById(R.id.first);
EditText secondeditText=(EditText)findViewById(R.id.second);
EditText thirdeditText=(EditText)findViewById(R.id.third);
EditText fourtheditText=(EditText)findViewById(R.id.fourth);

     firsteditText.requestFocus();

Upvotes: 8

Related Questions