Jump to content

multithreathing


emanuelx

Recommended Posts

boas pessoal há pouco tempo iniciei-me na programação para android, que é a mesma coisa que java, mas agora que queria usar o multithreathing e não consigo usar pois lá no meio do procedimento tem refererencias para mudar uma barra de progresso e umas alertbox.

já tentei de várias formas mas não estou a conseguir, será que alguem me pode explicar como funcionam?

final ProgressBar barra = (ProgressBar) findViewById(R.id.barra);

    AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

    String xmltext="";

        

    

    try {
            int barrap=0;
            barra.setVisibility(0);
            URL textUrl = new URL("http://www.legendas-zone.org/rss1.php");
            BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));  
            String StringBuffer;
            
            barra.setMax(bufferReader.readLine().length());
            while ((StringBuffer = bufferReader.readLine()) != null) {
                barrap+=StringBuffer.length();
                barra.setProgress(barrap);
                xmltext += StringBuffer;
                }
            bufferReader.close();   
            System.out.println(xmltext);
            Thread thread = new Thread((Runnable) this);
            thread.start();
            
            lerxml(xmltext.replace("&", "e"));
            Toast.makeText(this, "Concluído!", Toast.LENGTH_SHORT).show();
        } 
                catch (MalformedURLException ex) 
            {            
                alertbox.setMessage(ex.toString());
                alertbox.show();
        } 
                catch (IOException e) 
            {
                alertbox.setMessage(e.toString());
                alertbox.show();
            }

com calma e sem stresses

Link to comment
Share on other sites

Aonde é que está o método run()?

Porque é que fazes cast?

"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Link to comment
Share on other sites

private void carregardados()
{
    final ProgressBar barra = (ProgressBar) findViewById(R.id.barra);
        
    
    final Handler myHandler = new Handler();
        
                
        (new Thread(new Runnable() {
                    
                    public void run() {
                        try {
                            int barrap=0;
                            String xmltext = null;
                        URL textUrl = new URL("http://www.legendas-zone.org/rss1.php");
                        final BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream()));  
                        String StringBuffer;                        
                            myHandler.post(new Runnable() {
                                public void run() {
                                    try {
                                        maxbarra(bufferReader.readLine().length());
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                }
                            });
                            while ((StringBuffer = bufferReader.readLine()) != null) {
                                     barrap+=StringBuffer.length();
                                     barra.setProgress(barrap);
                                     xmltext += StringBuffer;
                                     }
                                bufferReader.close();  
                                sendmsg("aa");
                            //lerxml(xmltext.replace("&", "e"));
                        } 
                        catch (MalformedURLException ex) 
                    {            
                        sendmsg(ex.toString());
                        
        	        } 
                        catch (IOException e) 
                    {
                        sendmsg(e.toString());
                        
                    }
                    
                    }
                })).start();
                
            }
Edited by emanuelx

com calma e sem stresses

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.