Reputation: 16364
In my application, I have multiple tabs. In one of the tabs, I have an EditText which needs to have focus by default when the user moves to that tab.
But, when the tab is changed, the EditText loses focus.
I tried all this.
In my Xml file to the EditText to which I want to have the focus.
<requestFocus />
In my java code onCreate()
userIdInput.post(new Runnable()
{
public void run()
{
userIdInput .requestFocus();
}
});
And also,
userIdInput.setFocusable(true);
userIdInput.setFocusableInTouchMode(true);
userIdInput.requestFocus();
But still, the focus is lost when the tab is changed. Can anyone tell me what I might be missing here ?
Upvotes: 0
Views: 609
Reputation: 18592
Assuming you have a different container layout for each of your tabs, implement the setOnFocusChangeListener()
for that container layout (one which contains the edit text) and inside the onFocusChange()
check if the container layout has focus, if yes, use
userIdInput.post(new Runnable()
{
public void run()
{
userIdInput .requestFocus();
}
});
Upvotes: 1