Reputation: 6134
After figuring out how to use a Recyclerview to display items, I've encountered a bug wherein the Recyclerview's items disappears when I switch between fragments.
Solution: It turns out that the Main Activity Xml gets replaced by the fragment then when I come back it inflates a blank fragment. All I had to do was to create a different fragment for the Main Activity.
Upvotes: 0
Views: 773
Reputation: 1385
To solve this go to your class where you're passing the arraylist of data to recyclerview adapter and simply put that arraylist into an companion object such that whenever it's recreated it would retain it's previous value eg: Put this inside your class:-
fun loaddataintoarrlist(){
//load your data into arraylist such that it's not empty
arrlist.add("abc")
}
companion object{
//Your arraylist
var arrlist:Arraylist?=null
}
Upvotes: 2