Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8572341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:59:14+00:00 2026-06-11T18:59:14+00:00

I have a process in a button (large process). I want to update the

  • 0

I have a process in a button (large process). I want to update the TextView with diferents values. Like:

  • Connecting…
  • Receiving Files…
  • Complete…

etc..

I’m using setText(); void, but I’m getting only the last value of setText();, in that case:

estatEdit.setText(“Tareas completadas!”);

Here is my 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 && (!str2.contains("PDA7-F@S-") && !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>=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 && (!str2.contains("PDA3-F@S-") && !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 > 0)
            {
                FinalSQL = LiniaSQL.replace("***** ", "");
                if(FinalSQL.contains("DELETE") && !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)) > 0) {
                          buffer.append(chr, 0, len);
                      }
                  } finally {
                      reader.close();
                  }
                  return buffer.toString();
              }




    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }

}

Thanks in advance!

David.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:59:16+00:00Added an answer on June 11, 2026 at 6:59 pm

    Internet connection is a blocking action, i.e. it blocks the UI until the action is complete (this is why only the last update is seen). You have to move it to a Thread (or even better to an AsyncTask). But then you get another problem, you cannot update UI from outside the main Thread. So, you have to use a Handler to update the UI.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process that runs long, and I want to update a label
I want to get specific counters for processes that I have process id's for.
I have a process which gives me continuously output in Screen. I want to
I have a process I want to run in the background of a page.
I have a process intensive task that I would like to run in the
I have a button that will launch a process that requires UAC elevation. I
I have a page with normal Ajax Update panel. There is a submit button
We have created a multi-threaded application which process/parse big files (few hundred MB's) simultaneously.
I have a PHP page, that on clicking the submit button process a few
I have a folder with a large amount of files inside of it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.