When I was going through RecyclerView i got a question. I have a RecyclerView list and on clicking on the list item, I can go to another recyclerView list (Just updated data in same RecyclerView). But when I tried to click on back button, My app closed directly. My question is how can I get back on previous list by onBackPressed method? I tried to save parent list variable in Application context variable and it was a success. But still got same problem when beck was pressed.
Asked
Active
Viewed 1,169 times
1 Answers
0
Have a global var, boolen mItemClicked = false
that you set to true when you click a list item. Then overwrite the onBackPressed
function like this:
@Override
public void onBackPressed()
{
if(mItemClicked) {
//update RecyclerView's data to initial values
mItemClicked= false;
}
else {
super.onBackPressed();
}
}

Evripidis Drakos
- 872
- 1
- 7
- 15