Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // An AsyncTask definition
- // The view in your UI that you want to update from the AsyncTask
- private ProgressBar asyncProgress;
- private TextView asyncTextView;
- private class MyAsyncTask extends AsyncTask<String, Integer, String> {
- @Override
- protected String doInBackground(String... parameter) {
- // Move to a background thread
- String result = "";
- int myProgress = 0;
- int inputLength = parameter[0].length();
- // perform background processing task, update myProgress
- for(int i = 1; i <= inputLength; i++) {
- myProgress = i;
- result = result + parameter[0].charAt(inputLength - i);
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) { }
- publishProgress(myProgress);
- }
- // return the value to be passed to onPostExecute
- return result;
- }
- @Override
- protected void onPreExecute() {
- asyncProgress.setVisibility(View.VISIBLE);
- }
- @Override
- protected void onProgressUpdate(Integer... progress) {
- asyncProgress.setProgress(progress[0]);
- }
- @Override
- protected void onPostExecute(String result) {
- asyncProgress.setVisibility(View.GONE);
- asyncTextView.setText(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement