java - calling getview() method in custom listview -
java - calling getview() method in custom listview -
i using custom listview text , arrow image @ right of list row.
i have following
1: mainactivity extends listactivity
2: specialadapter extends arrayadapter have getview() method.
3: classes sqlite dtabase.
i have edittext , add together button storing new text database list. code here .
onclicklistener listeneradd = new onclicklistener() { @override public void onclick(view v) { comment comment = null; edittext edit = (edittext) findviewbyid(r.id.edit_txt); string number = edit.gettext().tostring(); if(!number.equals("")){ comment = datasource.createcomment(number); adapter.add(comment); edit.settext(""); adapter.notifydatasetchanged(); } else{ toast.maketext(getapplicationcontext(), "please come in number",toast.length_short).show(); } } };
i totally confused in class should utilize code ???
how phone call getview method ??
i used code in main class throws exception.
the more of import adapter should use???
adapter code here..
public class specialadapter extends arrayadapter<comment>{ context context; int layoutresourceid; comment data[]= null; // comment datacom[] = null; public specialadapter(context context, int layoutresourceid,comment[] values) { super(context, layoutresourceid, values); this.layoutresourceid = layoutresourceid; this.context = context; this.data = values; } @override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; weatherholder holder = null; if(row == null) { layoutinflater inflater = ((activity)context).getlayoutinflater(); row = inflater.inflate(layoutresourceid, parent, false); holder = new weatherholder(); holder.imgicon = (imageview)row.findviewbyid(r.id.img_arrow); holder.txttitle = (textview)row.findviewbyid(r.id.tv_number); row.settag(holder); } else { holder = (weatherholder)row.gettag(); } comment comment = data[position]; holder.txttitle.settext(comment.getcomment()); holder.imgicon.setimageresource(r.drawable.arrow); homecoming row; } static class weatherholder { imageview imgicon; textview txttitle; } }
you have set onclicklistner
in yourclass extending actvity
. create sure yourxml file contains button. otherwise exception.
i.e
setcontentview(r.layout.yourxmllayoutfilename);
your button should in yourxmllayoutfilename
xml file
java android android-arrayadapter custom-lists
Comments
Post a Comment