Custom Listview(or Adapter) that allows updating a row instead of adding one. (Android) -


i have listview. now, i'm using switch-case, i'm comparing getview() method's position id obtained server in form of json response. suppose id myobjectarraylist.get(poisition).getidforcomparison. myadapter.java

 arraylist<myobject> myobjectarraylist;         int counter = 0;      @override             public view getview(final int position, view convertview, viewgroup parent) {           switch(myobjectarraylist.get(poisition).getidforcomparison){          case x:          if (myobjectarraylist.get(position).getidforcomparison) == myobjectarraylist.get(nextposition).getidforcomparison){         "update same row concatenating new text exisiting"         }         else{         "insert next row"         }           }     } 

so, need keep collecting information json object in same row until myobjectarraylist.get(poisition).getidforcomparison same current , next position. if not, want allow addition of new row.

logic processing should never done inside getview method called multiple random times leads inconsistency in conditionals returning false though truthy statement.

assuming myadapter.java extends baseadapter there 2 other methods in baseadapter can overridden

  1. baseadapter.getviewtypecount()
  2. baseadapter.getitemviewtype(int position)

your logic should placed inside getitemviewtype(int position), , corresponding view modifications should done inside it.

getviewtypecount() - returns number of types of views created getview(int, view, viewgroup). each type represents set of views can converted in getview(int, view, viewgroup). if adapter returns same type of view items, method should return 1

hope helps


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -