xamarin - Getting wrong position in custom ListView while scrolling -


i getting wrong position in custom listview while scrolling.

i have tried viewholder pattern , arrayadapter both giving same problem.

if reproduce code using java getting proper position while scrolling.

so xamarin architecture bug ?

below sample code:

activity class

namespace arrayadapterdemoapp {     [activity(label = "arrayadapterdemoapp", mainlauncher = true,      icon ="@drawable/icon")]     public class mainactivity : activity     {         private static list<databean> _itemslist = new list<databean>();         private static customadapter _adapter;         private listview _listview;          protected override void oncreate(bundle bundle)         {             base.oncreate(bundle);              // set our view "main" layout resource             setcontentview(resource.layout.main);              // our button layout resource,             // , attach event             _listview = findviewbyid<listview>(resource.id.mylist);             databean obj1 = new databean();             obj1.name = "aa";             obj1.city = "11";             _itemslist.add(obj1);              databean obj2 = new databean();             obj2.name = "bb";             obj2.city = "22";             _itemslist.add(obj2);              databean obj3 = new databean();             obj3.name = "cc";             obj3.city = "33";             _itemslist.add(obj3);              ...              databean obj15 = new databean();             obj15.name = "oo";             obj15.city = "1010";             _itemslist.add(obj15);              _adapter = new customadapter(this, _itemslist);             _listview.adapter = _adapter;         }     } } 

custom adapter

namespace arrayadapterdemoapp {     public class customadapter : arrayadapter<databean>      {         private class taskviewholder : java.lang.object         {             public textview tvname;             public textview tvcity;         }          list<databean> listdata;         activity _context;         int _position;          public customadapter(activity context, list<databean> datalist)             : base(context, resource.layout.adapter_row, datalist)         {             this._context = context;             this.listdata = datalist;         }          public override long getitemid(int position)         {             return position;         }          public override int count         {             { return listdata.count; }         }          //with view holder         public override view getview(int position, view convertview, viewgroup parent)         {             databean data = listdata[position];             taskviewholder viewholder= null; // view lookup cache stored in tag             if (convertview == null)             {                 viewholder = new taskviewholder();                 layoutinflater inflater = layoutinflater.from(_context);                 convertview = inflater.inflate(resource.layout.adapter_row, parent, false);                  viewholder.tvname = convertview.findviewbyid<textview>(resource.id.text1);                 viewholder.tvcity = convertview.findviewbyid<textview>(resource.id.text2);                   convertview.tag = viewholder;             }              if(viewholder==null)             {                 viewholder = (taskviewholder)convertview.tag;             }              viewholder.tvname.text = data.name;             viewholder.tvcity.text = data.city;              return convertview;         }     } } 

databean class

namespace arrayadapterdemoapp {     public class databean     {         public string name { get; set; }         public string city { get; set; }     } } 

i had same issue resolved tag position view.for example.

//iv_delete imageview

holder.iv_delete.tag = position;

and position tag

for me int finalposition = (integer)holder.iv_delete.tag.intvalue();

enjoy!!!!!


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -