android - Custom ListView does not show up -
i trying use custom listview
inside fragment
using custom cursoradapter
, far unable display listview
.
what doing wrong?
my fragment
import android.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.listview; public class mylistfragment extends fragment { private customcursoradapter mcustomcursoradapter; private listview mlistview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_mylist, container, false); //cursoradapter mcustomcursoradapter = new customcursoradapter(view.getcontext(), null, 0); //listview mlistview = (listview) view.findviewbyid(r.id.itemslist); mlistview.setadapter(mcustomcursoradapter); return view; } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); } }
my mainactivity
import android.app.activity; import android.app.fragmentmanager; import android.os.bundle; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); fragmentmanager fragmentmanager = getfragmentmanager(); if (fragmentmanager.findfragmentbyid(android.r.id.content) == null) { mylistfragment mylistfragment = new mylistfragment(); fragmentmanager.begintransaction().add(android.r.id.content, mylistfragment).commit(); } } }
customcursoradapter
import android.content.context; import android.database.cursor; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.cursoradapter; import android.widget.textview; public class customcursoradapter extends cursoradapter { private layoutinflater mlayoutinflater; public customcursoradapter(context context, cursor c, int flags) { super(context, c, flags); mlayoutinflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); } @override public void bindview(view view, context context, cursor cursor) { textview textview = (textview) view.findviewbyid(r.id.itemtextview); textview.settext(cursor.getstring(cursor.getcolumnindex(databasehelper.column_name_item))); } @override public view newview(context context, cursor cursor, viewgroup parent) { return mlayoutinflater.inflate(r.layout.itemslist, parent, false); } }
here's doing.
in fragment, doing in onactivitycreated() this:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view campainview = inflater.inflate(r.layout.campaignview, container, false); return campainview; } public void onactivitycreated(bundle savedinstancestate) { // todo auto-generated method stub super.onactivitycreated(savedinstancestate); string[] s = {"a","b","c","d","b","c","d","b","c","d","b","c","d","b","c","d","b","c","d"}; arraylist<string> alist = new arraylist<string>(); for(string s1:s){ alist.add(s1); } listview lv1= (listview)getactivity().findviewbyid(r.id.campaignlistview); lv1.setadapter(new arrayadapter<string>(getactivity(), android.r.layout.simple_list_item_1,alist)); }
this work's me , can instead of using adapter iv'e used, can use cursor adapter. if it's still not working, issue cursor adapter or values null that's coming database.
let me know if working.. luck .. :)
Comments
Post a Comment