android - How can I get a TextView from a ListView WITHOUT Click? -
android - How can I get a TextView from a ListView WITHOUT Click? -
i'm starting out in android , creating basic to-do-list using listactivity
. essentially, every time item (an entry) clicked, item marked (or unmarked) in it's corresponding sharedpreferences
file. in addition, corresponding textview
slashed (or unslashed) using setpaintflags
, follows:
protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); sharedpreferences savedlist = this.getpreferences(0); string item = savedlist.getstring(position + "", ""); if ( item.contains(checked) ) { item = item.replace(checked,""); saveitem(item, position); ((textview)v).setpaintflags( ((textview)v).getpaintflags() & (~ paint.strike_thru_text_flag)); } else { item = checked + item; saveitem(item,position); ((textview)v).setpaintflags( ((textview)v).getpaintflags() | paint.strike_thru_text_flag); } }
(the "checked" here string.) in oncreate
method, read sharedpreferences
file reload items in checklist, , whichever ones have been marked, like, again, strike out, follows:
for (int = 0;; i++){ pos = i; listitems = savedlist.getstring(""+i,""); if (listitems.matches("")){ //if first entry in saved file empty, stop loop break; } else if(listitems.contains(checked)){ listitems.replace(checked,""); listitems.add(listitems); adapter.notifydatasetchanged(); textview textview = (textview) (getlistview()).getchildat(i); textview.setpaintflags( textview.getpaintflags() | paint.strike_thru_text_flag); } else{ listitems.add(listitems); adapter.notifydatasetchanged(); } }
this doesn't seem work, 2 problems arising: first, though remove "checked" checked, item appearing in listview
still has "checked". , secondly, strikes don't appear, leading me believe corresponding textview
hasn't been picked up.
edit: forgot include something.
the view v
isn't textview, if textview have id, can utilize v.findviewbyid
find target textview on onlistitemclick
;
textview textview = (textview) (getlistview()).getchildat(i);
you can utilize getlistview().getchildat(i).findviewbyid
android listview textview
Comments
Post a Comment