Seenu69
Seenu69

Reputation: 1054

How to get the cursor on Editext of child item of the Recyclerview when the new item is added to it?

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

Answers (2)

Puneet Ahuja
Puneet Ahuja

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

JAD
JAD

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

Related Questions