Monday, 15 February 2010

java - How to childclicklistner of expandable listview in Android? -



java - How to childclicklistner of expandable listview in Android? -

i have add together text , buttons in expandable listview , done retrieve sqlite info in expandable_listview. want phone call activity added on expandablelistview.

here activity class

public class my_project extends expandablelistactivity { expandablelistview explistview; button btnnewproject; button btn_myprojectdefinemyteam; dbhelper databasehelper; sqlitedatabase db; imageview imgbuttonback; list dispdatalist; string[] array; string[] task_title_size; string[] task_start_date_size; string[] task_completiondate_size; string[] task_completiontime_size; string[] task_description_size; string[] task_status_size; string[] task_isactive_size; string[] dtrprojectnamesize; public static final string task_title = "task_titles"; public static final string task_start_date = "start_date"; public static final string task_completiondate = "completion_date"; public static final string task_completiontime = "completion_time"; public static final string task_description = "task_description"; public static final string task_status = "task_status"; public static final string task_isactive ="is_active"; private int childclickstatus=-1; expandablelistadapter madapter; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.my_project); imgbuttonback = (imageview)findviewbyid(r.id.imagbackbutton);//imageview imgbuttonback; imgbuttonback.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent iback = new intent(my_project.this , menu.class); startactivity(iback); finish(); } }); explistview = (expandablelistview) findviewbyid(android.r.id.list); databasehelper = new dbhelper(getapplicationcontext()); dispdatalist=databasehelper.viewmyprojectdetals(); dtrprojectnamesize=new string[dispdatalist.size()]; system.out.println(" dtrprojectnamesize = " + dtrprojectnamesize); if ( dispdatalist.size() > 6 ) { task_title_size=(string[])dispdatalist.get(0); task_start_date_size=(string[]) dispdatalist.get(1); task_completiondate_size = (string[])dispdatalist.get(2); task_completiontime_size=(string[])dispdatalist.get(3); task_description_size=(string[]) dispdatalist.get(4); task_status_size = (string[])dispdatalist.get(5); task_isactive_size = (string[])dispdatalist.get(6); for(int i=0;i<task_title_size.length;i++) { system.out.println("new info :"+task_title_size[i]); } list<map<string, string>> groupdata = new arraylist<map<string, string>>(); list<list<map<string, string>>> childdata = new arraylist<list<map<string, string>>>(); (int = 0; < task_title_size.length ; i++) { map<string, string> curgroupmap = new hashmap<string, string>(); groupdata.add(curgroupmap); curgroupmap.put(task_title,"" +task_title_size[i]); list<map<string, string>> children = new arraylist<map<string, string>>(); map<string, string> curchildmap = new hashmap<string, string>(); children.add(curchildmap); curchildmap.put(task_start_date,"" +task_start_date_size[i]); curchildmap.put(task_completiondate,"" +task_completiondate_size[i]); curchildmap.put(task_completiontime,"" +task_completiontime_size[i]); curchildmap.put(task_description,"" +task_description_size[i]); curchildmap.put(task_status,"" +task_status_size[i]); curchildmap.put(task_isactive,"" +task_isactive_size[i]); childdata.add(children); } madapter =new simpleexpandablelistadapter( this, groupdata, r.layout.list_group, new string[] { task_title }, new int[] {r.id.lbllistheader }, childdata, r.layout.child_item, new string[] { task_start_date , task_completiondate , task_completiontime , task_description , task_status , task_isactive}, new int[] { r.id.textview_projectdetails , r.id.textone , r.id.texttwo , r.id.textthree , r.id.textfour, r.id.textfive} ); explistview.setadapter(madapter); } explistview.setongroupclicklistener(new ongroupclicklistener() { @override public boolean ongroupclick(expandablelistview parent, view v, int groupposition, long id) { homecoming false; } }); //edittexttaskname = (edittext)findviewbyid(r.id.task_name); explistview.setongroupexpandlistener(new ongroupexpandlistener() { @override public void ongroupexpand(int groupposition) { toast.maketext(getapplicationcontext(), dtrprojectnamesize.length + " expanded", toast.length_short).show(); } }); explistview.setongroupcollapselistener(new ongroupcollapselistener() { @override public void ongroupcollapse(int groupposition) { toast.maketext(getapplicationcontext(), dtrprojectnamesize.length + " collapsed", toast.length_short).show(); } }); explistview.setonchildclicklistener(new onchildclicklistener() { @override public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) { // todo auto-generated method stub final string selectedexpchild = (string) madapter.getchild( groupposition, childposition); system.out.println(" selectedexpchild = " + selectedexpchild); toast.maketext(getapplicationcontext(), childposition+"clicked", toast.length_long).show(); homecoming true; } }); btnnewproject = (button)findviewbyid(r.id.buttonmyproject_newproject); btnnewproject.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent = new intent(my_project.this , add_project.class); startactivity(i); finish(); } }); btn_myprojectdefinemyteam = (button)findviewbyid(r.id.buttonmyprojectdefinemyteam); btn_myprojectdefinemyteam.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent = new intent(my_project.this , team_member.class); startactivity(i); finish(); } }); } private class myexpandable_listadapter extends baseexpandablelistadapter { private context _context; private list<string > _listdataheader; // header titles //list<map<string, string>> groupdata; // kid info in format of header title, kid title private hashmap<string, list<string>> _listdatachild; context context; public myexpandable_listadapter(my_project my_project, list<map<string, string>> groupdata, int listgroup, string[] strings, int[] is, list<list<map<string, string>>> childdata, int childitem, string[] strings2, int[] is2) { // todo auto-generated constructor stub } public object getchild(int groupposition, int childposition) { //this.get(groupposition).getchildren().get(childposition); string strchildposition = this._listdatachild.get(this._listdataheader.get(groupposition)).get(childposition); system.out.println("child position =" + strchildposition); homecoming this._listdatachild.get(this._listdataheader.get(groupposition)) .get(childposition); } //call when kid row clicked @override public long getchildid(int groupposition, int childposition) { //****** when kid row clicked function phone call *******//* //log.i("noise", "parent == "+groupposition+"= kid : =="+childposition); if( childclickstatus!=childposition) { childclickstatus = childposition; toast.maketext(getapplicationcontext(), "parent :"+groupposition + " kid :"+childposition , toast.length_long).show(); } homecoming childposition; } public view getchildview1(int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { homecoming parent; } @override public view getchildview(int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { final string childtext = (string) getchild(groupposition, childposition); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.child_item, null); } textview txtlistchild = (textview) convertview.findviewbyid(r.id.textview_projectdetails); textview txtonelistchild = (textview)convertview.findviewbyid(r.id.textone); textview txttwolistchild = (textview)convertview.findviewbyid(r.id.texttwo); textview txtthreelistchild = (textview)convertview.findviewbyid(r.id.textthree); textview txtfourlistchild = (textview)convertview.findviewbyid(r.id.textfour); textview txtfivelistchild = (textview)convertview.findviewbyid(r.id.textfive); txtlistchild.settext(childtext); txtonelistchild.settext(childtext); txttwolistchild.settext(childtext); txtthreelistchild.settext(childtext); txtfourlistchild.settext(childtext); txtfivelistchild.settext(childtext); convertview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent = new intent(my_project.this ,assign_task.class); startactivity(i); finish(); } }); button btnassgntask = (button)convertview.findviewbyid(r.id.button_editedtask); btnassgntask.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub } }); button btnviewtask = (button)convertview.findviewbyid(r.id.buttonviewtask); btnviewtask.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub } }); homecoming convertview; } @override public int getchildrencount(int groupposition) { homecoming this._listdatachild.get(this._listdataheader.get(groupposition)) .size(); } @override public object getgroup(int groupposition) { homecoming this._listdataheader.get(groupposition); } @override public int getgroupcount() { homecoming _listdataheader.size() ;//groupdata.size(); } /**06-21 11:34:03.903: e/androidruntime(544): caused by: java.lang.nullpointerexception 06-21 11:34:03.903: e/androidruntime(544): @ com.sentaca.android.accordion.my_project$myexpandable_listadapter.getgroupcount(my_project.java:330) 06-21 11:34:03.903: e/androidruntime(544): @ android.widget.expandablelistconnector.getcount(expandablelistconnector.java:396) 06-21 11:34:03.903: e/androidruntime(544): @ android.widget.listview.setadapter(listview.java:454) 06-21 11:34:03.903: e/androidruntime(544): @ android.widget.expandablelistview.setadapter(expandablelistview.java:475) 06-21 11:34:03.903: e/androidruntime(544): @ com.sentaca.android.accordion.my_project.oncreate(my_project.java:146) **/ @override public long getgroupid(int groupposition) { homecoming groupposition; } @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) { string headertitle = (string) getgroup(groupposition); if (convertview == null) { layoutinflater infalinflater = (layoutinflater) this._context .getsystemservice(context.layout_inflater_service); convertview = infalinflater.inflate(r.layout.list_group, null); } textview lbllistheader = (textview) convertview .findviewbyid(r.id.lbllistheader); lbllistheader.settypeface(null, typeface.bold); lbllistheader.settext(headertitle); homecoming convertview; } @override public boolean hasstableids() { homecoming false; } @override public boolean ischildselectable(int groupposition, int childposition) { homecoming true; } } } error log cat 06-21 12:43:21.564: i/system.out(897): str_task_titles :task 1 06-21 12:43:21.564: i/system.out(897): str_start_date :20-06-2014 06-21 12:43:21.564: i/system.out(897): str_completion_date :6-20-2014 06-21 12:43:21.564: i/system.out(897): str_completion_time :17-30 06-21 12:43:21.564: i/system.out(897): str_task_description :fill form 06-21 12:43:21.564: i/system.out(897): str_task_status :pending 06-21 12:43:21.574: i/system.out(897): str_is_active :yes 06-21 12:43:21.596: i/system.out(897): dtrprojectnamesize = [ljava.lang.string;@40526c28 06-21 12:43:21.596: i/system.out(897): new info :task 1 06-21 12:43:27.654: d/androidruntime(897): shutting downwards vm 06-21 12:43:27.654: w/dalvikvm(897): threadid=1: thread exiting uncaught exception (group=0x40015560) 06-21 12:43:27.707: e/androidruntime(897): fatal exception: main 06-21 12:43:27.707: e/androidruntime(897): java.lang.classcastexception: java.util.hashmap 06-21 12:43:27.707: e/androidruntime(897): @ com.sentaca.android.accordion.my_project$5.onchildclick(my_project.java:192) 06-21 12:43:27.707: e/androidruntime(897): @ android.widget.expandablelistview.handleitemclick(expandablelistview.java:588) 06-21 12:43:27.707: e/androidruntime(897): @ android.widget.expandablelistview.performitemclick(expandablelistview.java:527) 06-21 12:43:27.707: e/androidruntime(897): @ android.widget.abslistview$performclick.run(abslistview.java:1812) 06-21 12:43:27.707: e/androidruntime(897): @ android.os.handler.handlecallback(handler.java:587) 06-21 12:43:27.707: e/androidruntime(897): @ android.os.handler.dispatchmessage(handler.java:92) 06-21 12:43:27.707: e/androidruntime(897): @ android.os.looper.loop(looper.java:123) 06-21 12:43:27.707: e/androidruntime(897): @ android.app.activitythread.main(activitythread.java:3683) 06-21 12:43:27.707: e/androidruntime(897): @ java.lang.reflect.method.invokenative(native method) 06-21 12:43:27.707: e/androidruntime(897): @ java.lang.reflect.method.invoke(method.java:507) 06-21 12:43:27.707: e/androidruntime(897): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 06-21 12:43:27.707: e/androidruntime(897): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 06-21 12:43:27.707: e/androidruntime(897): @ dalvik.system.nativestart.main(native method)

thanks.

at my_project.java:141, replace:

string[] array = new string[] { task_start_date , task_completiondate , task_completiontime , task_description , task_status , task_isactive};

with:

string[][] array = new string[][] { task_start_date , task_completiondate , task_completiontime , task_description , task_status , task_isactive};

remove previous changes had suggested (i.e. maintain same code before above change).

java android expandablelistadapter

No comments:

Post a Comment