java - Display Data from Database in ListView With Fragment -


i trying display data second column of database listview inside scrollview.

i using fragment, i'm having problem using getsupportloadermanager().initloader(1, data, this); sais "getsupportloadermanager() undefined method", create new class inside fragment experiment, , result there no error when execute it, there's nothing happening ie. expected data not showing in listview.

here layout:

main.xml

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/main_body"     android:layout_width="match_parent"     android:layout_height="match_parent"      android:fillviewport="true"     android:background="@drawable/b">     <listview         android:id="@+id/lv_countries_main"         android:layout_width="match_parent"         android:layout_height="wrap_content" />  </scrollview> 

and main.java

public class main extends fragment {         public main() {     }      button btn;     textview tx;     edittext inputsearch;     arrayadapter<string> dataadapter = null;     view rootview;     scrollview mainbody;     listview mlvcountries;     simplecursoradapter mcursoradapter;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         rootview = inflater.inflate(r.layout.main, container, false);         sethasoptionsmenu(true);         getactivity().settitle("search");          mlvcountries = (listview)rootview.findviewbyid(r.id.lv_countries_main);          mainbody = (scrollview)rootview.findviewbyid(r.id.main_body);     return rootview; }  public class mainmain extends fragmentactivity implements loadercallbacks<cursor> {         public void oncreate(bundle savedinstancestate){             super.oncreate(savedinstancestate);             mlvcountries.setonitemclicklistener(new onitemclicklistener() {                 public void onitemclick(adapterview<?> parent, view view, int position, long id) {                     intent countryintent = new intent(getactivity().getapplicationcontext(), countryactivity.class);                     // creating uri fetch country details corresponding selected listview item                     uri data = uri.withappendedpath(countrycontentprovider.content_uri, string.valueof(id));                     // setting uri data on intent                     countryintent.setdata(data);                     // open activity                     startactivity(countryintent);                 }             });             // defining cursoradapter listview                   mcursoradapter = new simplecursoradapter(getactivity().getbasecontext(),                     android.r.layout.simple_list_item_1,                     null,                     new string[] { searchmanager.suggest_column_text_1},                     new int[] { android.r.id.text1}, 0);             // setting cursor adapter country listview             mlvcountries.setadapter(mcursoradapter);             // getting intent invoked activity             intent intent = getactivity().getintent();                   // if activity invoked selecting item suggestion of search dialog or              // listview of searchactivity              if(intent.getaction().equals(intent.action_view)){                  intent countryintent = new intent(getactivity(), countryactivity.class);                 countryintent.setdata(intent.getdata());                 startactivity(countryintent);                 getactivity().finish();                      }else if(intent.getaction().equals(intent.action_search)){ // if activity invoked, when user presses "go" in keyboard of search dialog                 string query = intent.getstringextra(searchmanager.query);                 dosearch(query);             }            }          private void dosearch(string query){             bundle data = new bundle();             data.putstring("query", query);             // invoking oncreateloader() in non-ui thread             getsupportloadermanager().initloader(1, data, this);                 }           /** method invoked initloader() */         @override         public loader<cursor> oncreateloader(int arg0, bundle data) {             uri uri = countrycontentprovider.content_uri;                    return new cursorloader(getbasecontext(), uri, null, null , new string[]{data.getstring("query")}, null);            }         /** method executed in ui thread, after oncreateloader() */         @override         public void onloadfinished(loader<cursor> arg0, cursor c) {              mcursoradapter.swapcursor(c);                }         @override         public void onloaderreset(loader<cursor> arg0) {          }     }     @override     public void oncreateoptionsmenu(menu menu, menuinflater inflater) {        // inflater.inflate.getmenuinflater();        inflater.inflate(r.menu.main_search_view, menu); //do not add otherwise searcview duplicate        menuitem menuitem = menu.finditem(r.id.search);        searchview searchview = (searchview) menuitem.getactionview();        searchview.seticonifiedbydefault(false);        searchview.setqueryhint("type something...");          int searchplateid = searchview.getcontext().getresources().getidentifier("android:id/search_plate", null, null);         view searchplate = searchview.findviewbyid(searchplateid);         if (searchplate!=null) {             searchplate.setbackgroundcolor(color.dkgray);             int searchtextid = searchplate.getcontext().getresources().getidentifier("android:id/search_src_text", null, null);             textview searchtext = (textview) searchplate.findviewbyid(searchtextid);             if (searchtext!=null) {                 searchtext.settextcolor(color.white);                 searchtext.sethinttextcolor(color.white);             }         }       // associate searchable configuration searchview         searchmanager searchmanager =                (searchmanager) getactivity().getsystemservice(context.search_service);         searchview =                 (searchview) menu.finditem(r.id.search).getactionview();         searchview.setsearchableinfo(                 searchmanager.getsearchableinfo(getactivity().getcomponentname()));          super.oncreateoptionsmenu(menu, inflater);     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar actions click         switch (item.getitemid()) {         case r.id.action_settings:             return false;         case r.id.search:             return true;             default:             break;         }         return false;     } } 

first, have put info in database in string []

go on columns first cursor count

set string[] length this, string [] values= new string [int count]

move on cursor again , insert string of each column in each position

when have filled info need database, define arrayadapter ... setlistadapter


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -