android - The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks<D>) keeps giving me not applicable error -
i'm stuck in code i'm using drawer layout , on fragment layout want display list of persons after getting database. in fragment class when query using cursor adapter , set list adapter error says:
the method initloader(int, bundle, loadermanager.loadercallbacks) in type loadermanager not applicable arguments (int, null, mainfragment).
where i'm going wrong, please help. if u need more info please ask. below fragment class , corresponding layout code. in advance.
fragment class:
import java.text.simpledateformat; import java.util.arraylist; import java.util.calendar; import java.util.collection; import java.util.date; import java.util.list; import java.util.locale; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import com.bnkinfotech.corporatedirectory.directory.mobile; import com.bnkinfotech.corporatedirectory.directory.telephone; import android.app.listfragment; import android.content.contentvalues; import android.content.context; import android.content.intent; import android.content.sharedpreferences; import android.content.sharedpreferences.editor; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.listadapter; import android.widget.listview; import android.widget.simplecursoradapter; import android.widget.toast; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; import android.support.v4.app.loadermanager.loadercallbacks; //import android.support.v4.app.listfragment; import android.support.v4.app.loadermanager; import android.support.v4.content.asynctaskloader; import android.support.v4.content.loader; import android.support.v4.content.cursorloader; import android.support.v4.widget.cursoradapter; public class mainfragment extends listfragment implements loadercallbacks<cursor> { string loginpref; string email; string updateddate; string onlineemail = null; sharedpreferences prefaccount; protected cursor cursor; protected listadapter adapter; protected sqlitedatabase db; public static string argaccountnumber = "account_list_number"; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { prefaccount = getactivity().getsharedpreferences("codiaccount", context.mode_private); onlineemail = prefaccount.getstring("email", "-1").tolowercase(); string directoryname = "codiapp" + onlineemail; sharedpreferences prefs = getactivity().getsharedpreferences(directoryname, context.mode_private); loginpref = prefs.getstring("login", "-1"); email = prefs.getstring("email", "-1").tolowercase(); updateddate = prefs.getstring("lastupdateddate", "-1"); view rootview = inflater.inflate(r.layout.main_fragment, container, false); return rootview; } @override public void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); } @override public void onstart() { super.onstart(); if (loginpref == "1") { showcontacts(); } else if (loginpref == "0") { //validate account intent verifyaccount = new intent(getactivity(), verifyaccountactivity.class); getactivity().startactivity(verifyaccount); } else { //email login intent checkemail = new intent(getactivity(), checkemailactivity.class); getactivity().startactivity(checkemail); } } public int showcontacts() { sharedpreferences prefaccount = getactivity().getsharedpreferences("codiaccount", context.mode_private); string onlineemail = prefaccount.getstring("email", "-1").tolowercase(locale.english); string directoryname = "codiapp" + onlineemail; sharedpreferences prefs = getactivity().getsharedpreferences(directoryname, context.mode_private); string loadxml = prefs.getstring("loadxml", "-1"); string groupby = prefs.getstring("groupby", "0"); if (loadxml == "-1") { loadxmlfile(); editor prefeditor = prefs.edit(); prefeditor.putstring("loadxml", "1"); string timestamp = new simpledateformat("yyyy-mm-dd hh:mm:ss").format(calendar.getinstance().gettime()); prefeditor.putstring("lastupdateddate", timestamp.tostring()); prefeditor.commit(); } string[] uibindfrom = { sqlitedb.first_name, sqlitedb.last_name }; int[] uibindto = { r.id.firstname, r.id.lastname }; getloadermanager().initloader(0, null, this); adapter = new simplecursoradapter( getactivity().getapplicationcontext(), r.layout.main_fragment, null, uibindfrom, uibindto, cursoradapter.flag_register_content_observer); setlistadapter(adapter); return 1; } public void loadxmlfile() { string response = ""; requestmanager rm = new requestmanager(); string x = ""; arraylist<mobile> arrmob; arraylist<telephone> arrtel; try { if(isvalidemail(email)) { string url = string.format("getdirectory/{0}", email); response = rm.getresponse(url); try { // create json array jsonarray llist=new jsonarray(response); // iterate json array each json object (int = 0; < llist.length(); i++) { jsonobject lobject=llist.getjsonobject(i); string fname=lobject.getstring("firstname"); string lname=lobject.getstring("lastname"); string gname=lobject.getstring("groupname"); jsonarray jsonarr= lobject.getjsonarray("mobilenumbers"); mobile[] mnumbers=new mobile[jsonarr.length()]; arrmob = new arraylist<mobile>(); for(int j=0;j<jsonarr.length();j++) { mnumbers[j]= (mobile) jsonarr.get(j); arrmob.add(mnumbers[j]); } jsonarray jsonarrtel= lobject.getjsonarray("telephonenumbers"); telephone [] tnumbers=new telephone[jsonarrtel.length()]; arrtel = new arraylist<telephone>(); for(int k=0;k<jsonarrtel.length();k++) { tnumbers[k]=(telephone) jsonarrtel.get(k); arrtel.add(tnumbers[k]); } string haddress=lobject.getstring("homeaddress"); string oaddress=lobject.getstring("officeaddress"); //code insert in sqlite database ..... directory dir = new directory(); dir.setfirstname(fname); dir.setlastname(lname); dir.setgroupname(gname); dir.setmobiles(arrmob); dir.settelephones(arrtel); dir.sethomeaddress(haddress); dir.setofficeaddress(oaddress); databasehandler dbhandler = new databasehandler(getactivity().getapplicationcontext()); sqlitedatabase sqlitedatabase = dbhandler.getwritabledatabase(); contentvalues contentvalues = new contentvalues(); contentvalues.put(databasehandler.id, dir.getid()); contentvalues.put(databasehandler.first_name, dir.getfirstname()); contentvalues.put(databasehandler.last_name, dir.getlastname()); contentvalues.put(databasehandler.group_name, dir.getgroupname()); contentvalues.put(databasehandler.mobiles, dir.getmobiles().tostring()); contentvalues.put(databasehandler.telephones, dir.gettelephones().tostring()); contentvalues.put(databasehandler.home_address, dir.gethomeaddress()); contentvalues.put(databasehandler.office_address, dir.getofficeaddress()); sqlitedatabase.insert(databasehandler.table_name_member, null, contentvalues); sqlitedatabase.close(); } } catch (jsonexception e) { e.printstacktrace(); } } else { string msg = "sorry, invalid email"; toast.maketext(getactivity().getapplicationcontext(), msg, toast.length_long).show(); } } catch (exception ex) { response = ex.getmessage().tostring(); } } public final static boolean isvalidemail(charsequence email) { if (email == null) { return false; } else { return android.util.patterns.email_address.matcher(email).matches(); } } @override public loader<cursor> oncreateloader(int arg0, bundle arg1) { string[] projection = { sqlitedb.id, sqlitedb.first_name, sqlitedb.last_name }; cursorloader cursorloader = new cursorloader(getactivity(), databaseaccessutility.content_uri, projection, null, null, null); return cursorloader; } @override public void onloadfinished(loader<cursor> arg0, cursor arg1) { ((simplecursoradapter) adapter).swapcursor(arg1); } @override public void onloaderreset(loader<cursor> arg0) { ((simplecursoradapter) adapter).swapcursor(null); } }
mainfragment layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:minwidth="25dp" android:minheight="25dp" android:id="@+id/flyoutcontent"> <linearlayout android:id="@+id/linlaheaderprogress" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" android:visibility="gone"> <progressbar android:id="@+id/pbheaderprogress" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </linearlayout> <relativelayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="8dp" > <textview android:id="@+id/firstname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="first" /> <textview android:id="@+id/lastname" android:layout_marginleft="6dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/firstname" android:text="last" /> </relativelayout> <linearlayout android:orientation="vertical" android:minwidth="25dp" android:minheight="25dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@android:id/empty"> <textview android:text="@string/nofavoritestext" android:textappearance="?android:attr/textappearancemedium" android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@+id/textview1" android:gravity="center" android:layout_marginleft="12dip" android:layout_marginright="12dip" android:textcolor="#ff5a5a5a" android:layout_margintop="80dip" /> </linearlayout> </linearlayout>
since using support library, use instead:
getactivity().getsupportloadermanager().initloader(0, null, this);
Comments
Post a Comment