android - ListView: how to access Item's elements programmatically from outside? -
i have next situation.
i have listview, each item of listview comprised of different widgets (textviews, imageviews, etc...) inflated form layout in getview()
method of custom adapter.
now, accomplish following:
when event triggered want alter background of view within item.
please how do it?
this the item layout:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/cardlayout" android:layout_width="320dp" android:layout_height="130dp" android:background="@android:color/transparent" android:orientation="vertical" android:paddingbottom="5dp" android:paddingright="5dp" android:paddingtop="5dp" > <framelayout android:layout_width="320dp" android:layout_height="117dp" > <view android:id="@+id/card" android:layout_width="320dp" android:layout_height="117dp" android:background="@drawable/card_selector" /> </framelayout> </linearlayout>
i need alter background of card
i have tried doing this:
view v=lv.getadapter().getview(index, null, lv); view card =(view)v.findviewbyid(r.id.card); card.setbackgroundresource(r.drawable.pressed_background_card);
but no success :-((
when event triggered should phone call notifydatasetchanged on adapter phone call 1 time again getview visible elements.
your getview method should take business relationship elements may have different background colors (and not forget set normal color if element doesn't need changed background, else recycling have many elements changed background when scroll)
edit :
i seek :
@override public view getview(int position, view convertview, viewgroup parent) { if(convertview == null) { convertview = layoutinflater.from(getcontext()).inflate(r.layout.card, parent, false); } //this part should optimised viewholder //because findviewbyid costly operation, that's not point of illustration cardview cardview =(cardview)convertview .findviewbyid(r.id.card); //i suppose card should determined adapter, not new 1 each time card card = getitem(position); //here should check sthg position presence in map or special state of card object if(mapcardwithspecialbackground.contains(position)) { card.setbackgroundresource(specialbackground); } else { card.setbackgroundresource(normalbackground); } cardview.setcard(card); homecoming convertview; }
and on special event add together position of item map , phone call notifydatasetchanged.
android listview
No comments:
Post a Comment