i'm using expandablelistview extending baseexpandablelistadapter in fragment , show inside viewpager. i'm trying show text of each textview of childs when click it. don't know why shut down app when press child item. me? thank lot!
here fragment , adapter:
public class savedtabsfragment extends fragment { private arraylist<string> parentitems = new arraylist<>(); private arraylist<object> childitems = new arraylist<>(); @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_explistview, null); expandablelistview elv = (expandablelistview) v.findviewbyid(r.id.expandablelistview1); elv.setgroupindicator(null); elv.setclickable(true); setgroupparents(); setchilddata(); savedtabslistadapter adapter = new savedtabslistadapter(parentitems, childitems); adapter.setinflater((layoutinflater) getactivity().getsystemservice(context.layout_inflater_service), this); elv.setadapter(adapter); // elv.setonchildclicklistener(new expandablelistview.onchildclicklistener() { // @override // public boolean onchildclick(expandablelistview parent, view v, int groupposition, int childposition, long id) { // toast.maketext(getactivity()," holaaa",toast.length_short).show(); // // return false; // } // }); return v; } public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); //todo } public static savedtabsfragment newinstance(){ savedtabsfragment savedtabsfragment = new savedtabsfragment(); bundle args = new bundle(); //todo info del bundle return savedtabsfragment; } public void setgroupparents() { parentitems.add("androwwid"); parentitems.add("core java"); parentitems.add("desktop java"); parentitems.add("enterprise java"); } public void setchilddata() { // android arraylist<string> child = new arraylist<>(); child.add("core"); child.add("games"); childitems.add(child); // core java child = new arraylist<>(); child.add("apache"); child.add("applet"); child.add("aspectj"); child.add("beans"); child.add("crypto"); childitems.add(child); // desktop java child = new arraylist<>(); child.add("accessibility"); child.add("awt"); child.add("imageio"); child.add("print"); childitems.add(child); // enterprise java child = new arraylist<>(); child.add("ejb3"); child.add("gwt"); child.add("hibernate"); child.add("jsp"); childitems.add(child); } public class savedtabslistadapter extends baseexpandablelistadapter { private arraylist<string> parentitems, child; private arraylist<object> childitems; private layoutinflater inflater; private activity activity; public savedtabslistadapter(arraylist<string> parentitems, arraylist<object> childitems) { this.childitems = childitems; this.parentitems = parentitems; } public int getgroupcount() { return parentitems.size(); } public int getchildrencount(int i) { return ((arraylist<string>) childitems.get(i)).size(); } public object getgroup(int i) { return parentitems.get(i); } public object getchild(int i, int i1) { return null; } public long getgroupid(int i) { return 0; } public long getchildid(int i, int i1) { return 0; } public boolean hasstableids() { return false; } @override public view getgroupview(int groupposition, boolean isexpanded, view convertview, viewgroup parent) { if (convertview == null) { convertview = inflater.inflate(r.layout.row, null); } ((checkedtextview) convertview).settext(parentitems.get(groupposition)); ((checkedtextview) convertview).setchecked(isexpanded); return convertview; } @override public view getchildview(int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { child = (arraylist<string>) childitems.get(groupposition); textview textview = null; if (convertview == null) { convertview = inflater.inflate(r.layout.group, null); } textview = new textview(savedtabsfragment.this.getactivity()); textview = (textview) convertview.findviewbyid(r.id.textview1); textview.settext(child.get(childposition)); textview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { toast.maketext(activity, child.get(childposition)+" holaaa", toast.length_short).show(); } }); return convertview; } @override public boolean ischildselectable(int i, int i1) { return true; } @override public void ongroupcollapsed(int groupposition) { super.ongroupcollapsed(groupposition); } @override public void ongroupexpanded(int groupposition) { super.ongroupexpanded(groupposition); } public void setinflater(layoutinflater inflater, savedtabsfragment savedtabsfragment) { this.inflater = inflater; // = savedtabsfragment; } } }
and here layout:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layout_fragment_exp" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <expandablelistview android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/expandablelistview1" android:layout_centerhorizontal="true" android:layout_alignparenttop="true" android:cachecolorhint="@android:color/transparent" android:divider="@android:color/transparent" android:dividerheight="20dp" android:childdivider="@android:color/transparent" android:scrollbarstyle="outsideoverlay" android:paddingbottom="7dp" android:paddingleft="9dp" android:paddingright="9dp" android:paddingtop="10dp" /> </relativelayout>
edit:
here logcat message:
05-08 11:58:12.395 18706-18706/com.example.julio.listviewactionbar e/androidruntime﹕ fatal exception: main process: com.example.julio.listviewactionbar, pid: 18706 java.lang.nullpointerexception @ android.widget.toast.<init>(toast.java:93) @ android.widget.toast.maketext(toast.java:241) @ com.example.julio.listviewactionbar.savedtabsfragment$savedtabslistadapter$1.onclick(savedtabsfragment.java:245) @ android.view.view.performclick(view.java:4569) @ android.view.view$performclick.run(view.java:18570) @ android.os.handler.handlecallback(handler.java:743) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5196) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:602) @ dalvik.system.nativestart.main(native method)
i think activity null. why dont pass getactivity in toast method below'.
toast.maketext(getactivity(), child.get(childposition)+" holaaa", toast.length_short).show();
Comments
Post a Comment