How to invoke the bootloader by clicking a button?
I am using Loader to load data from my database ...
When my activity starts ... the loader will call asynthesis correctly ...
but I don't know how to load data when I click on the button!
if "onCreateLoader" is called automatically when the activity starts, how to avoid this?
Solved:
Using FragmentActivity ...
forceload () is used because loadInBackgroung doesn't work!
used getSupportLoaderManager () because getLoaderManager () didn't work either because presumably the library is giving problems!
but ... I don't know ... I'm not convinced, but ... so far 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;
}
}
+3
source to share
1 answer
just press restartLoader on button click:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getLoaderManager().restartLoader(YOUR_LOADER_ID, null, mYourLoaderCallbacks);
}
});
+3
source to share