java - ExpandableListView Change layout of first child -
i'm trying load 2 different layouts expandable list child. keep getting null pointer, me sounds !=0
not working way intended. doing wrong?
public view getchildview(final int groupposition, final int childposition, boolean islastchild, view convertview, viewgroup parent) { layoutinflater inflater = context.getlayoutinflater(); log.e("comments", "ok position: " + childposition); if (convertview == null) { if(childposition==0){ //first view convertview = inflater.inflate(r.layout.comments_create_comment, null); }else { //second view convertview = inflater.inflate(r.layout.comments_expandable_list_child, null); } } if(childposition!=0){ textview item = (textview) convertview.findviewbyid(r.id.comments_expandable_list_child_text_view); imageview delete = (imageview) convertview.findviewbyid(r.id.comments_expandable_list_child_delete); //throwing null pointer exception @ delete.setonclick //i'm guessing it's still using first view here somehow? delete.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { list<string> child = comments_feed_collection.get(group_list.get(groupposition)); child.remove(childposition); notifydatasetchanged(); } }); item.settext(laptop); } return convertview; }
exact print out:
04-22 10:27:58.762 21013-21013/com.myapp e/comments﹕ ok position: 0 04-22 10:27:58.772 21013-21013/com.myapp i/editor﹕ setup window support handles 04-22 10:27:58.772 21013-21013/com.myapp e/comments﹕ ok position: 1 04-22 10:27:58.772 21013-21013/com.myapp w/dalvikvm﹕ threadid=1: thread exiting uncaught exception (group=0x4183fda0) 04-22 10:27:58.792 21013-21013/com.myapp e/oh nooo﹕ java.lang.nullpointerexception @ comments.commentsexpandablelistadapter.getchildview(commentsexpandablelistadapter.java:58)
your problem lies here:
if (convertview == null) { if(childposition==0){ //first view convertview = inflater.inflate(r.layout.comments_create_comment, null); }else { //second view convertview = inflater.inflate(r.layout.comments_expandable_list_child, null); } }
convertview
null getchildtypecount
times. if didn't override method, convertview
inflated once. childposition==0
case. can find here documentation
Comments
Post a Comment