Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use AsyncTask and set new TextView in every onProgressUpdate:</p> <pre><code>protected class InitTask extends AsyncTask&lt;Context, Integer, String&gt; { // -- run intensive processes here // -- notice that the datatype of the first param in the class definition matches the param passed to this method // -- and that the datatype of the last param in the class definition matches the return type of this method @Override protected String doInBackground( Context... params ) { //-- on every iteration //-- runs a while loop that causes the thread to sleep for 2 minutes //-- publishes the progress - calls the onProgressUpdate handler defined below //-- and increments the counter variable i by one int i = 0; while( i &lt;= 50 ) { try{ Thread.sleep( 2*60*1000); publishProgress( i ); i++; } catch( Exception e ){ Log.i("makemachine", e.getMessage() ); } } return "COMPLETE!"; } // -- gets called just before thread begins @Override protected void onPreExecute() { Log.i( "makemachine", "onPreExecute()" ); super.onPreExecute(); } // -- called from the publish progress // -- notice that the datatype of the second param gets passed to this method @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); Log.i( "makemachine", "onProgressUpdate(): " + String.valueOf( values[0] ) ); _percentField.setText( ( values[0] * 2 ) + "%"); _percentField.setTextSize( values[0] ); } // -- called if the cancel button is pressed @Override protected void onCancelled() { super.onCancelled(); Log.i( "makemachine", "onCancelled()" ); _percentField.setText( "Cancelled!" ); _percentField.setTextColor( 0xFFFF0000 ); } // -- called as soon as doInBackground method completes // -- notice that the third param gets passed to this method @Override protected void onPostExecute( String result ) { super.onPostExecute(result); Log.i( "makemachine", "onPostExecute(): " + result ); _percentField.setText( result ); _percentField.setTextColor( 0xFF69adea ); _cancelButton.setVisibility( View.INVISIBLE ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload