Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating textView while button execution? - Android
    primarykey
    data
    text
    <p>I have a process in a button (large process). I want to update the TextView with diferents values. Like:</p> <ul> <li>Connecting...</li> <li>Receiving Files...</li> <li>Complete... </li> </ul> <p>etc..</p> <p>I'm using setText(); void, but I'm getting only the last value of setText();, in that case:</p> <p>estatEdit.setText("Tareas completadas!");</p> <p>Here is my code...</p> <pre><code>public class sincroGeneral extends Activity implements OnClickListener { private static final String CATEGORIA = "libro"; private static final String HOST = "192.168.1.165"; private static final int PORT = 9889; private static final int PORTDATOS = 9888; int filesize=6022386; int bytesRead; int current = 0; byte [] mybytearray = new byte [filesize]; byte buffer[] = new byte[1024]; byte buffer2[] = new byte[1024]; byte bufferArxiu[] = new byte[2048]; int s; int s2; String Benvinguda; String compra; EditText estatEdit; EditText editInflated; File myfile; SQLiteDatabase baseDatos; LinearLayout mainLayout; View view2; /** Called when the activity is first created. */ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.sincrolayout); Button b = (Button) findViewById(R.id.BotoEnviarSincro); b.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Button b = (Button) findViewById(R.id.BotoEnviarSincro); estatEdit = (EditText) findViewById(R.id.editSincro); estatEdit.setText("Enviando petición..."); b.setClickable(false); b.setFocusable(false); b.setEnabled(false); ProcesRebre(); b.setClickable(true); b.setFocusable(true); b.setEnabled(true); } }); } private void mostrarMensaje(String mensaje) { Toast.makeText(this, mensaje, 500).show(); } private void ProcesRebre() { Socket sockDatos = null; Socket clientSocket = null; DataOutputStream sortida; DataInputStream entrada; BufferedReader inFromServer; DataOutputStream sortidaDatos; DataInputStream entradaDatos; BufferedReader inFromServerDatos; try { estatEdit.setText("Conectando..."); clientSocket = new Socket(HOST, PORT); sortida = new DataOutputStream(clientSocket.getOutputStream()); entrada = new DataInputStream(clientSocket.getInputStream()); inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sortida.writeBytes("FAS4-F@S-1-F@S- 1.0.152-F@S-"); Log.i("Enviat","OK"); clientSocket.setSoTimeout(30000); s = entrada.read(buffer); String str = new String(buffer, "UTF8"); clientSocket.setSoTimeout(0); Log.i("Rebut","OK"); if(str.contains("PDA1-F@S-")) { sockDatos = new Socket(HOST, PORTDATOS); estatEdit.setText("Esperando archivo...."); sortidaDatos = new DataOutputStream(sockDatos.getOutputStream()); entradaDatos = new DataInputStream(sockDatos.getInputStream()); inFromServerDatos = new BufferedReader(new InputStreamReader(sockDatos.getInputStream())); sortidaDatos.writeBytes("FAS4-F@S-1-F@S- 1.0.150-F@S-"); if(sockDatos.isConnected()) { System.out.println("Conectat amb port 9888"); } File carpetaSincro = new File(Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/"); carpetaSincro.mkdirs(); File ArxiuSincro = new File (Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/sincroorders.zip"); if(ArxiuSincro.exists()) { ArxiuSincro.delete(); } File ArxiuSincro2 = new File (Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/sincroorders.zip"); ArxiuSincro2.createNewFile(); sortida.writeBytes("FAS2-F@S-"); String str2= ""; clientSocket.setSoTimeout(30000); while(true &amp;&amp; (!str2.contains("PDA7-F@S-") &amp;&amp; !str2.contains("PDAERR1-F@S-"))) { s2 = entrada.read(buffer2); str2 = new String(buffer2, "UTF8"); } clientSocket.setSoTimeout(0); String replace1 = str2.replace("PDA7-F@S-", ""); String replace2 = replace1.replace(" ", ""); String tamanyArxiu = replace2.replace("-F@S-ZIP",""); int bufferZip = Integer.parseInt(tamanyArxiu); boolean in; s2 = 0; sockDatos.setSoTimeout(30000); RandomAccessFile archivo = new RandomAccessFile(Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/sincroorders.zip", "rw"); long tamArxActual = 0; while(bufferZip&gt;=tamArxActual) { sockDatos.setSoTimeout(10000); s2 = entradaDatos.read(bufferArxiu); estatEdit.setText("Recibiendo archivo...."); archivo.write(bufferArxiu); tamArxActual = archivo.length(); Thread.sleep(2); } sockDatos.setSoTimeout(0); estatEdit.setText("Archivo recibido"); str2 = ""; clientSocket.setSoTimeout(30000); while(true &amp;&amp; (!str2.contains("PDA3-F@S-") &amp;&amp; !str2.contains("PDAERR1-F@S-"))) { s2 = entrada.read(buffer2); str2 = new String(buffer2, "UTF8"); } clientSocket.setSoTimeout(0); if(str2.contains("PDA3-F@S-")) { sortida.writeBytes("FAS7-F@S-"); Thread.sleep(2000); sortida.writeBytes("FAS6-F@S-"); } sockDatos.close(); clientSocket.close(); String pathZip = Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/sincroorders.zip"; String directoriExtraccio = Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/"; String pathTxt = Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/SincrofitPC.txt"; UnzipUtility unzipper = new UnzipUtility(); try { unzipper.unzip(pathZip, directoriExtraccio); } catch (Exception ex) { System.out.print("No s'ha pogut descomprimir l'arxiu"); ex.printStackTrace(); } File f = new File(Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/SincrofitPC.dll"); f.renameTo(new File(Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/SincrofitPC.txt")); importarSincro(); } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void importarSincro() throws SQLException, IOException { int contador = 0; String LiniaSQL; FileInputStream fstream = new FileInputStream(Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/SincrofitPC.txt"); DataInputStream DataInFile = new DataInputStream(fstream); BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(Environment.getExternalStorageDirectory()+"/OrdersCE/Syncro/SincrofitPC.txt"), "Latin-1")); String FinalSQL = ""; baseDatos = openOrCreateDatabase("BBDD", MODE_WORLD_WRITEABLE, null); baseDatos.execSQL("BEGIN"); while ((LiniaSQL = br.readLine()) != null) { if(contador &gt; 0) { FinalSQL = LiniaSQL.replace("***** ", ""); if(FinalSQL.contains("DELETE") &amp;&amp; !FinalSQL.contains("DELETE FROM")) { FinalSQL = FinalSQL.replace("DELETE", "DELETE FROM"); try{ baseDatos.execSQL(FinalSQL); }catch(SQLiteException e){ } } else { try{ baseDatos.execSQL(FinalSQL); }catch(SQLiteException e){ } } LiniaSQL = ""; } contador++; } baseDatos.execSQL("COMMIT"); estatEdit.setText("Tareas completadas!"); baseDatos.close(); } ///////////////////////////////////////// public static String deserializeString(File file) throws IOException { int len; char[] chr = new char[4096]; final StringBuffer buffer = new StringBuffer(); final FileReader reader = new FileReader(file); try { while ((len = reader.read(chr)) &gt; 0) { buffer.append(chr, 0, len); } } finally { reader.close(); } return buffer.toString(); } public void onClick(View arg0) { // TODO Auto-generated method stub } } </code></pre> <p>Thanks in advance!</p> <p>David.</p>
    singulars
    1. This table or related slice is empty.
    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