emanuelx Posted August 24, 2012 at 09:29 AM Report Share #473344 Posted August 24, 2012 at 09:29 AM 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 More sharing options...
brunoais Posted August 24, 2012 at 10:22 AM Report Share #473347 Posted August 24, 2012 at 10:22 AM 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 More sharing options...
emanuelx Posted August 24, 2012 at 11:06 AM Author Report Share #473359 Posted August 24, 2012 at 11:06 AM (edited) 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 August 24, 2012 at 11:10 AM by emanuelx com calma e sem stresses Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now