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
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
Post a Comment