Created
September 19, 2022 13:34
-
-
Save anta40/8a34e383e92ac68e58757d67708073e0 to your computer and use it in GitHub Desktop.
MainActivity Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.annotation.NonNull; | |
import androidx.annotation.Nullable; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.app.LoaderManager; | |
import android.content.Loader; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.ProgressBar; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<BigData> { | |
TextView textView1; | |
ProgressBar progressBar1; | |
Button button1; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
textView1 = (TextView)findViewById(R.id.textView1); | |
progressBar1 = (ProgressBar)findViewById(R.id.progressBar1); | |
button1 = (Button) findViewById(R.id.button1); | |
getLoaderManager().initLoader(0, null, this); | |
button1.setOnClickListener(v -> { | |
progressBar1.setVisibility(View.VISIBLE); | |
getLoaderManager().restartLoader(0, null, this); | |
}); | |
} | |
@Override | |
public Loader<BigData> onCreateLoader(int i, Bundle bundle) { | |
Log.d("test", "------------onCreateLoader"); | |
BigDataLoader loader = new BigDataLoader(getApplicationContext()); | |
loader.forceLoad(); | |
return loader; | |
} | |
@Override | |
public void onLoadFinished(Loader<BigData> loader, BigData data) { | |
textView1.setText(data.at(0)); | |
progressBar1.setVisibility(View.GONE); | |
} | |
@Override | |
public void onLoaderReset(Loader<BigData> loader) { | |
Log.d("test", "------------onLoaderReset"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment