Reputation: 1054
I have a RecyclerView where I'm adding the child items to it on click of the button dynamically. Each Child Item has a Editext. When a new child item is been added to the RecyclerView the Editetext of the new item should get the focus. How can I do it?
Upvotes: 0
Views: 1221
Reputation: 157
You can request a focus inside your Adapter.
Something like this:
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
((ViewHolder) holder).yourEditText.requestFocus(); // It will set a focus on your edittext whenever the child is getting created
}
Upvotes: 3
Reputation: 1160
The proper way to do this is by setting focus to EditText in your RecyclerView.Adapter
, onBindViewHolder(ViewHolder, int)
method.
Then set focus normally using: yourEditText.requestFocus();
Upvotes: 2