0

java.lang.IllegalStateException: Two different ViewHolders have the same stable ID. Stable IDs in your adapter MUST BE unique and SHOULD NOT change. Where to create ids?

I'm creating a blogging app where i have different viewholder. For views to disable shuffle, and to provide correct positioning i need to provide stable ids. Hence I need to know the correct process of overriding getItemId().

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vikash Sharma
  • 539
  • 8
  • 13
  • Its also better if you say, what do you want to achieve...? – Xenolion Apr 12 '18 at 20:25
  • @Xenolion i m creating a blogging app where i have different viewholder and for views to disable shuffle and to provide correct positioning i need to provide stable ids, hence i need to know the correct process of overriding getItemId(). – Vikash Sharma Apr 12 '18 at 20:29
  • Now I have got you, You should override the method `getItemViewType` in your adapter and return different ints depending on the View Type lets say form Swaggish view holder return 1 for that position, for a shuffle view holder return 3 or else. And getViewType in the onCreate and onBindViewHolder – Xenolion Apr 12 '18 at 21:10
  • Stable ids, complicated.. – Xenolion Apr 12 '18 at 21:10
  • any reference code for this?? – Vikash Sharma Apr 12 '18 at 21:45
  • Check the documentation or start here for any adapter even recyclerView adapter https://stackoverflow.com/questions/5300962/getviewtypecount-and-getitemviewtype-methods-of-arrayadapter – Xenolion Apr 13 '18 at 00:20

0 Answers0