Boa tarde galera, estou com um problema aqui faz horas.
É o seguinte tenho uma tela e um botão, qndo eu clico no botao ele inicializa uma thread e executa um metodo que exibi uma lista.
e o problema é, ele executa o metodo certinho, mas nao exibe a lista, ele mostra minha activity vazia sem os dados.
Veja como estou fazendo:
[code] mDialog = ProgressDialog.show(SincronizaDados_activity.this,
“Aguarde”, “Carregando Lista…”, false, false);
new Thread(new Runnable() {
@Override
public void run() {
ativaThread();
}
}).start();[/code]
Meu ativaThread:
[code]
private void ativaThread() {
try {
mostraLista();
mDialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage() + e.getCause());
mDialog.dismiss();
}
mHandler.post(new Runnable() {
@Override
public void run() {
System.out.println("Fim do progres..");
}
});
}[/code]
E o meu mostraLista:
public void mostraLista() {
aguaApp = (AguaApp) getApplication();
contriLista = new ArrayList<ContribuinteJson>();
enderecoLista = new ArrayList<Endereco>();
contriLista = aguaApp.getDataManager().buscaContribuinte();
enderecoLista = aguaApp.getDataManager().getEnderecoList();
setListAdapter(new ContribuinteAdapter(this, contriLista, enderecoLista));
}
No ativaThread ele passa o try e tenta executar o metodo, qndo termina o metodo ele cai no catch e exibe a msg de erro.
12-02 17:00:01.463: W/System.err(22061): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
12-02 17:00:01.463: W/System.err(22061): at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
12-02 17:00:01.473: W/System.err(22061): at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.requestLayout(View.java:8125)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.requestLayout(View.java:8125)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.requestLayout(View.java:8125)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.requestLayout(View.java:8125)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.requestLayout(View.java:8125)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.requestLayout(View.java:8125)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.setFlags(View.java:4501)
12-02 17:00:01.473: W/System.err(22061): at android.view.View.setVisibility(View.java:3030)
12-02 17:00:01.473: W/System.err(22061): at android.widget.AdapterView.updateEmptyStatus(AdapterView.java:727)
12-02 17:00:01.473: W/System.err(22061): at android.widget.AdapterView.checkFocus(AdapterView.java:697)
12-02 17:00:01.473: W/System.err(22061): at android.widget.ListView.setAdapter(ListView.java:437)
12-02 17:00:01.473: W/System.err(22061): at android.app.ListActivity.setListAdapter(ListActivity.java:267)
12-02 17:00:01.473: W/System.err(22061): at br.com.agua.SincronizaDados_activity.mostraLista(SincronizaDados_activity.java:129)
12-02 17:00:01.473: W/System.err(22061): at br.com.agua.SincronizaDados_activity.ativaThread(SincronizaDados_activity.java:98)
12-02 17:00:01.483: W/System.err(22061): at br.com.agua.SincronizaDados_activity.access$0(SincronizaDados_activity.java:94)
12-02 17:00:01.483: W/System.err(22061): at br.com.agua.SincronizaDados_activity$1.run(SincronizaDados_activity.java:74)
12-02 17:00:01.483: W/System.err(22061): at java.lang.Thread.run(Thread.java:1096)
12-02 17:00:01.483: I/System.out(22061): Only the original thread that created a view hierarchy can touch its views.null
12-02 17:00:01.503: I/System.out(22061): Fim do progres..
Estou postando aqui pq sem usar thread ele executa normal e exibe a lista, tem algo de errado sera? Obrigado. =]