cursor - getLoaderManager: in an activity -
i writing app wimmone watch: no orientation changes, small simple screen, , android version 7.
i got first android app running, based on book, had fragment. fragments added complications not want deal with.
my second app has similar structure: list of items select item see or update details. trying read cursor, , create array call "setlistadapter(lstadapter);".
i started with:
getloadermanager().initloader(0, null, this);
got error:
the method initloader(int, bundle, loadermanager.loadercallbacks) in type loadermanager not applicable arguments (int, null, phonelistactivity)
so tried suggestion:
getloadermanager().initloader(0, null, (android.app.loadermanager.loadercallbacks<d>) this);
got error:
the method initloader(int, bundle, loadermanager.loadercallbacks) type loadermanager refers missing type d
so tried this:
getloadermanager().initloader(0, null, (android.app.loadermanager.loadercallbacks) this);
and got error:
type safety: unchecked invocation initloader(int, null, loadermanager.loadercallbacks) of generic method initloader(int, bundle, loadermanager.loadercallbacks) of type loadermanager
several postings said use version below 11
getsupportloadermanager().initloader(0, null, this);
but gives me error:
the method getsupportloadermanager() undefined type phonelistactivity
i have seen not use "getloadermanager: in activity.
so doing wrong?
- or how read cursor , create list without creating complexities of fragment?
- am missing import?
many thanks, clark
below have:
package com.wimmone.phonenos; import android.view.menu; import android.annotation.targetapi; import android.app.activity; import android.app.listactivity; import android.content.contenturis; import android.content.contentvalues; import android.content.context; import android.content.dialoginterface; import android.content.dialoginterface.ondismisslistener; import android.database.cursor; import android.net.uri; import android.app.application; import android.content.intent; import android.database.cursor; import android.os.build; import android.os.bundle; import android.support.v4.app.listfragment; import android.support.v4.app.loadermanager; import android.support.v4.app.loadermanager.loadercallbacks; import android.support.v4.content.cursorloader; import android.support.v4.content.loader; import android.support.v4.widget.simplecursoradapter; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.view.onclicklistener; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.button; import android.widget.listadapter; import android.widget.listview; import android.widget.toast; import android.widget.adapterview; import android.widget.adapterview.onitemselectedlistener; import java.text.simpledateformat; import java.util.arraylist; import java.util.date; import java.util.list; import java.io.bufferedreader; import java.io.file; import java.io.filereader; import java.io.filewriter; import java.io.ioexception; import android.os.environment; import com.wimm.framework.app.dialog; public class phonelistactivity extends listactivity implements loadercallbacks<cursor> { private simplecursoradapter madapter; list strrecid = new arraylist(); private listadapter lstadapter; string strphonegroup = ""; string strphonename = ""; string strphonehome = ""; string strphonecell = ""; string strphonework = ""; private button btn_add; list strrecord = new arraylist(3); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.phone_list_activity); string[] stritems = new string[] {phoneprovider.column_phone_name}; int[] icnt = new int[] { r.id.text1 }; madapter = new simplecursoradapter(this, r.layout.phone_row, null, stritems, icnt, 0); log.d("phonenos***", "x oncrt: x02 start"); setlistadapter(madapter); //getloadermanager().initloader(0, null, this); //getloadermanager().initloader(0, null, this); getsupportloadermanager().initloader(0, null, this); //----------------------------------------------- // define add button button btnadd = (button) findviewbyid(r.id.btn_add); btnadd.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.d("phonenos***", "s create view btnaddevent:"); } } ); //----------------------------------------------- // define exit button button btnexit = (button) findviewbyid(r.id.btn_exit); btnexit.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { log.d("phonenos***", "s create view btnexit:"); //toast.maketext(this, "good bye", //toast.length_short).show(); // application.onterminate(); finish(); } } ); //----------------------------------------------- // define export button button btnexport . . . } //=============================================================== // data base routines load cursor @override public loader<cursor> oncreateloader(int ignored, final bundle args) { log.d("eventlst","s loadcsr"); return new cursorloader(this, phoneprovider.content_uri, null, null, null, null); // log.d("phonenos***","x loadcsr"); } @override public void onloadfinished(loader<cursor> loader, cursor cursor) { // log.d("phonenos***","0 loadfin"); int irecno = 0; int rowno = 0; int ibucnt = 0; string strpath = ""; madapter.swapcursor(cursor); strrecid.clear(); strrecord.clear(); strrecord.add(0, "mm-dd-yy: event name"); cursor.movetofirst(); log.d("eventlst","1 loadfin do"); // read cursor , add list while (cursor.isafterlast() == false) { irecno = irecno + 1; // - table has 4 columns, read them string array: strc string strc[] = { (cursor.getstring(0)), (cursor.getstring(1)), (cursor.getstring(2)), (cursor.getstring(3)), (cursor.getstring(4)), (cursor.getstring(5)) }; string strrowno = (cursor.getstring(0)); strphonegroup = (cursor.getstring(1)); strphonename = (cursor.getstring(2)); strphonehome = (cursor.getstring(3)); strphonecell = (cursor.getstring(4)); strphonework = (cursor.getstring(5)); log.d("phonenos***","4 loadcsr:" + "i:" + irecno + "=" + strrowno + "n:" + strphonename); // - concatenate group , name 1 string, add table strrecord.add(irecno, strphonegroup + "/" + strphonename); // - save record number each event in strrecid // - records sorted date, need save rowid pass // edit screen strrecid.add((cursor.getstring(0))); ibucnt = ibucnt + 1; cursor.movetonext(); } // --------------------end of while loop //cursor.close(); lstadapter = new arrayadapter<string>(this, r.layout.phone_row, r.id.text1, strrecord); // * call setlistadapter()informs listfragment how fill listview // * here use arrayadapter setlistadapter(lstadapter); // log.d("eventlst","8 loadcsr:" + "alldone"); } @override public void onloaderreset(loader<cursor> loader) // called when last cursor provided onloadfinished() above // closed { // log.d("eventlst","x loadrst"); // initrun remove below madapter.swapcursor(null); } }
since no 1 answered, re-did program , got working. needed use "extends launcheractivity" (for wimmone). since dealing small database on smart watch, loader isn't needed anyway, dropped use of loader , used cursor directly. seems faster.
Comments
Post a Comment