In preference change listener I have set it to download new data using Loader
and then fill the ListView
, but only the onCreateLoader()
function is called when I change the preference, the onLoadFinished()
callback function remains uncalled, hence my ListView
in not updated with new data, I also happen to have a refresh button that does the same thing i.e. downloads the data gain and fills the list with new data but here the onLoadFinished()
is called hence by updating the list.
The refresh button code
case R.id.menu_refresh :
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
if(isConnected)
{
getSupportLoaderManager().initLoader(0,null,this).forceLoad();
}
else {
Toast.makeText(this,"No Internet",Toast.LENGTH_SHORT).show();
}
break;
The SharedPreference listener code :
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
if(isConnected)
{
//delfromold();
getSupportLoaderManager().initLoader(0,null,this).forceLoad();
Log.v("Prefrences Changed",s);
}
}
EDIT
Loader Implementation
public class Loade extends AsyncTaskLoader<ArrayList<CustomL>>{
Context mCon;
public Loade(Context context) {
super(context);
mCon = context;
}
@Override
public ArrayList<CustomL> loadInBackground() {
ArrayList<CustomL> maList = null;
try {
Log.v("Loader","Called");
maList = GetList.makelist(mCon);
} catch (JSONException e) {
e.printStackTrace();
}
return maList;
}
}
Loader :
public Loader<ArrayList<CustomL>> onCreateLoader(int id, Bundle args) {
return new Loade(this);
}
public void onLoadFinished(Loader<ArrayList<CustomL>> loader, ArrayList<CustomL> data) {
Log.v("Load","Finished");
maklst(data);
}