Ben
Ben

Reputation: 3804

RecylerView Data Update Always Brings Focus to First Item

I got stuck on an issue when updating a RecylerView with a new ArrayList that includes an EditText. Whenever the RecylerView is updated with the new the ArrayList the program always selects the EditText of the first item in the RecyclerView.

There are Listeners that call the update function below each time there is a change of focus. So in other words, you can't effectively select any other EditText item in the RecylerView because when the first item loses focus, the RecyclerView updates with the new ArrayList and then automatically selects the EditText of the first item in the RecyclerView.

Is it a default that a notifyDataSetChanged() just automatically selects the first item? Or perhaps because of some way I set up the adapter?

private void refreshRecyclerList() {

    // Set titles for the Recycler View Items
    textInputList.clear();
    textInputList.add(new EditTextRecyclerItem("Monthly on New Stuff", stringSpendingMonthly));
    textInputList.add(new EditTextRecyclerItem("Yearly on New Stuff", stringSpendingAnnually));

    //mAdapter.updateArrayList(textInputList);
    mAdapter.notifyDataSetChanged();
}

I'm new to Android so please forgive if this is a simple fix that I've overlooked.

Upvotes: 2

Views: 2271

Answers (1)

Nidhi Desai
Nidhi Desai

Reputation: 91

If you calling this mAdapter.notifyDataSetChanged() then it means whole recyclerview is refreshing, So if you want to focus on changed item myAdapter.notifyItemInserted(position) or myAdapter.notifyItemChanged() or you can scroll your RecyclerView by recyclerview.scrollToPosition()

Please try and revert me if it is not working.

Upvotes: 1

Related Questions