listview - Update custom gridview from custom list adapter android -



listview - Update custom gridview from custom list adapter android -

i have listview contains set of custom view. within each custom view gridview.

i want able update background of each cell in gridview when user clicks checkbox in custom view.

here custom view

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <relativelayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingleft="10dp" android:paddingright="10dp" > <textview android:id="@+id/lbllistheader" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textsize="32sp" /> <checkbox android:id="@+id/lblheadercheckbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:focusable="false" android:layout_centervertical="true" /> </relativelayout> <ca.package.customgridview android:id="@+id/gridview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:clickable="false" android:gravity="center" android:numcolumns="7" android:padding="10dp" android:stretchmode="columnwidth" clickable="true" />

here layout each grid cell

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/griditem" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="vertical" android:clickable="true" > <textview android:id="@+id/grid_itemtxt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"> </textview> </linearlayout>

here how fill list

explistview = (listview) this.findviewbyid(r.id.event_list); preparelistdata(); listadapter = new customadapter(this, listdataheader, listdatachild, listchildboolean); explistview.setadapter(listadapter);

here getview method in custom adapter listview

public view getview(int groupposition, view convertview, viewgroup parent) { final int gp = groupposition; string headertitle = (string) getgroup(groupposition); // boolean bool = _listdataboolean.get(groupposition); boolean bool = currentcalendarevents.get(groupposition).getalert(); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_group, null); } string[] info = new string[14]; list<string> times = _currentlistdatachild.get(_currentlistdataheader .get(groupposition)); data[0] = "su"; data[1] = "m"; data[2] = "tu"; data[3] = "w"; data[4] = "th"; data[5] = "f"; data[6] = "sa"; data[7] = times.get(6); // sun data[8] = times.get(0); // mon data[9] = times.get(1); // tues data[10] = times.get(2); // wed data[11] = times.get(3); // thurs data[12] = times.get(4); // fri data[13] = times.get(5); // sat arraylist<boolean> boolarray = _listchildboolean.get(_currentlistdataheader .get(groupposition)); final gridview gridview = (gridview) convertview.findviewbyid(r.id.gridview); final gridadapter adapter = new gridadapter(this._context, data, boolarray); gridview.setadapter(adapter); textview lbllistheader = (textview) convertview .findviewbyid(r.id.lbllistheader); lbllistheader.settypeface(null, typeface.bold); lbllistheader.settext(headertitle); final checkbox chk2 = (checkbox) convertview .findviewbyid(r.id.lblheadercheckbox); chk2.setchecked(bool); chk2.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { if (chk2.ischecked()) { currentcalendarevents.get(gp).setalert(true); currentcalendarevents.get(gp).setdaystrue(); // want update list here log.i(log_tag, "box checked"); } else { currentcalendarevents.get(gp).setalert(false); currentcalendarevents.get(gp).setdaysfalse(); // , here log.i(log_tag, "box not checked"); } } }); convertview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.i(log_tag, "gridview clicked"); currentcalendarevents.get(gp).setbooldays(adapter.gethashmap()); } }); homecoming convertview; }

here gridadapter

public class gridadapter extends baseadapter { private context context; private string[] items; private arraylist<boolean> boolarray; private arraylist<view> views; layoutinflater inflater; public gridadapter(context context, string[] items, arraylist<boolean> boolarray) { this.context = context; this.items = items; this.boolarray = boolarray; this.views = new arraylist<view>(); inflater = (layoutinflater) this.context .getsystemservice(context.layout_inflater_service); } public view getview(final int position, view convertview, viewgroup parent) { if (convertview == null) { convertview = inflater.inflate(r.layout.grid_cell, null); final textview tv = (textview) convertview .findviewbyid(r.id.grid_itemtxt); tv.settext(items[position]); if (position < 7) { convertview.setbackgroundcolor(color.dkgray); tv.settextsize(typedvalue.complex_unit_sp, 24); tv.settextcolor(color.white); tv.settypeface(null, typeface.bold); tv.setlines(2); } else { log.e("blerp", "test : " + items[position]); if (!items[position].equals("")) { if (boolarray.get(position % 7)) { convertview.setbackgroundcolor(context.getresources() .getcolor(r.color.lightgreen)); } else { convertview.setbackgroundcolor(color.ltgray); } tv.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (boolarray.get(position % 7)) { ((view) tv.getparent()) .setbackgroundcolor(color.ltgray); boolarray.set(position % 7, false); } else { ((view) tv.getparent()) .setbackgroundcolor(context .getresources().getcolor( r.color.lightgreen)); boolarray.set(position % 7, true); } } }); } else convertview.setbackgroundcolor(color.ltgray); tv.settextsize(typedvalue.complex_unit_sp, 18); tv.setlines(2); } } homecoming convertview; } @override public int getcount() { homecoming items.length; } @override public object getitem(int position) { homecoming items[position]; } @override public long getitemid(int position) { homecoming position; } public hashmap<string,boolean> gethashmap() { hashmap<string, boolean> hm = new hashmap<string,boolean>(); hm.put("sun", boolarray.get(0)); hm.put("mon", boolarray.get(1)); hm.put("tues", boolarray.get(2)); hm.put("wed", boolarray.get(3)); hm.put("thurs", boolarray.get(4)); hm.put("fri", boolarray.get(5)); hm.put("sat", boolarray.get(6)); homecoming hm; } }

any help appreciated, can post more of code if need be.

initiate gridview , checkbox in adapter class (using find view id). pass if (checkbox.ischecked) { gridview.setbackgroundcolor(color.rgb(x,y,z)))}

android listview gridview android-custom-view

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -