android - Listview returns less children than the actual data feed -
is there row limit on listview? utilize fragment display listview , feed 32 records, when implement click returns has 12 rows; here on click function:
public void onlistitemclick(listview listview, view view, int position, long id) { super.onlistitemclick(listview, view, position, id); selected_position = position; if (listview.getchildcount() > 0) { listview.getchildat(position).setbackgroundcolor( color.parsecolor("#036287")); } }
what happens when listview.getchildat(position) executed , position number above 11 throws error. @ same time on tablet can see rows, don't appear in same listview first 12 records.
any ideas might issue?
another issue when alter color way, see several items selected, not 1. illustration in smaller scale explain it
--
item 1 item 2 item 3 item 4if max position 2, , select item 1, item 1 , item 3 lights up. if select item 2 - item 2 , item 4 lights up. if select item 3 - item 1 , item 3 lights , on.
it's frustrating, because can't view need, because seems several views contained @ position or in variable view returned on list item click.
the fact info (a list<> suppose) utilize feed view has size of 32, doesn't mean listview has 32 kid views.
the list view have smallest number of views plenty fill listview (in case happens 11)
if want alter color of views either can manipulate "view" parameter receive in listener:
public void onlistitemclick(listview listview, view view, int position, long id) { super.onlistitemclick(listview, view, position, id); view.setbackgroundcolor([your color here]); }
or add together corresponding info data model utilize feed adapter, , phone call notifydatasetchanged on list
public void onlistitemclick(listview listview, view view, int position, long id) { super.onlistitemclick(listview, view, position, id); yourobject yourobject = yourobjectlist.get(position); yourobject.clicked = true; }
then in getview
@override public view getview(int position, view convertview, viewgroup parent) { [...] yourobject yourobject = yourobjectlist.get(position); if(yourobject.clicked) { convertview.setbackgroundcolor([your color here]) } else { convertview.setbackgroundcolor([your other color here]) } }
for case i'd utilize first option, sec ono useful in scenarios when don't have direct reference view (like if happened in background)
android listview android-listview
No comments:
Post a Comment