I use the Loader to load data from my database...
When my activity start... the loader call the asynctask correctly...
but I don't know how to load data just when I click on a button!
if "onCreateLoader", called automatically when activity start, how avoid that?
Solved:
Using FragmentActivity...
used forceload() because the loadInBackgroung didn't work!
used getSupportLoaderManager() because getLoaderManager() didn't work too
both because supposedly the library gives problems!
but... I don't know... I'm not convinced, but...
for now, it works! :P
public void onClick(View v) {
switch(v.getId()){
case R.id.button:
if(getSupportLoaderManager().getLoader(0) == null){
getSupportLoaderManager().initLoader(0, null, this).forceLoad();
}else{
getSupportLoaderManager().restartLoader(0, null, this).forceLoad();
}
break;
case R.id.another:
Toast.makeText(this, "another", Toast.LENGTH_SHORT).show();
break;
}
}
simply call restartLoader when clicking button :
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getLoaderManager().restartLoader(YOUR_LOADER_ID, null, mYourLoaderCallbacks);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With