Android: notifydatachanged not updating listview -



Android: notifydatachanged not updating listview -

when user clicks item on list view, changing background color manually of selected listview item. plan on changing more background, (eventually icons , more), hence need listview redraw itself.

the problem when notifydatachanged nil happens. because of log's placed in functions, when item clicked, can verify onitemclick triggered, , notifydatasetchanged phone call made adapter.

i expect "getview" should called 1 time again each position, info gets linked views. not occuring. there no sign of of happening. missing here?

class myonitemclicklistener implements adapterview.onitemclicklistener{ @override public void onitemclick(final adapterview<?> parent, view view, final int position, long id) { log.i(tag, "listview on click " + position); mylistadapter adapter = (mylistadapter) parent.getadapter(); adapter.mselected = position; adapter.notifydatasetchanged(); } } class mylistadapter extends baseadapter{ public list<string> mtxtcontents; public int mgroupcount; public int mselected; public void setdata(list<string> txtcontents){ mtxtcontents = txtcontents; mgroupcount = txtcontents.size(); } @override public void registerdatasetobserver(datasetobserver observer) { // todo auto-generated method stub } @override public void notifydatasetchanged() { log.i(tag, "notify info set changed"); // todo auto-generated method stub super.notifydatasetchanged(); } @override public void unregisterdatasetobserver(datasetobserver observer) { // todo auto-generated method stub } @override public int getcount() { log.i(tag, "nva panel grouping count " + mgroupcount); homecoming mgroupcount; } @override public object getitem(int position) { // todo auto-generated method stub homecoming null; } @override public long getitemid(int position) { homecoming position; } @override public boolean hasstableids() { // todo auto-generated method stub homecoming false; } @suppresslint("inflateparams") @override public view getview(int position, view convertview, viewgroup parent) { log.i(tag, "get view, " + position); if(convertview == null){ layoutinflater li = layoutinflater.from(getactivity()); convertview = li.inflate(r.layout.lvitem_navpanel, parent, false); } textview tv = (textview) convertview.findviewbyid(r.id.tv_txtdata); tv.settext(mtxtcontents.get(position)); if(mselected == position){ convertview.setbackgroundcolor(color.parsecolor("#00ff00")); }else{ convertview.setbackgroundcolor(getresources().getcolor(android.r.color.transparent)); } homecoming convertview; } @override public int getitemviewtype(int position) { // todo auto-generated method stub homecoming 0; } @override public int getviewtypecount() { // todo auto-generated method stub homecoming 1; } @override public boolean isempty() { // todo auto-generated method stub homecoming false; } @override public boolean areallitemsenabled() { // todo auto-generated method stub homecoming true; } @override public boolean isenabled(int position) { // todo auto-generated method stub homecoming true; } }

try setting adapter 1 time again after modify it. so:

mylistadapter adapter = (mylistadapter) parent.getadapter(); adapter.mselected = position; parent.setadapter(adapter);

the new phone call setadapter clear recycler.

edit:

i'm not sure why you're using pattern posted above (to me looks unnecessary boilerplate , processing, maybe have special need), next might of help you

in onclick listener can like

textview txtview = (textview)listview.getchildat(position); txtview.setbackgroundcolor(color.red); txtview.settext("new text");

this automatically apply changes list item.

if require refresh whole row can do

view view = list.getchildat(position); list.getadapter().getview(position, view, list);

source

android listview

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -