Bonjour à tous,

Dans le cadre de mon initiation à Android, je cherche a remplir une ListView dans un Thread.

Voici un bout de mon code très basique :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
final ArrayAdapter<String> a = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1);
ListView vi = (ListView)getActivity().findViewById(R.id.domainListView);
vi.setAdapter(a);
new Thread( new Runnable() {    
@Override
                public void run() {  
                    for(int i=0; i<10; i++) {
                        a.add("toto");
                    }
                }
  }).start();
Or ceci ne semble pas etre vraiment autorisé, j'obtiens l'exception suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
only the original thread that created a view hierarchy can touch its views
Existe t'il une alternative pour mettre à jour ma list view dans un Thread ?

Merci d'avance,
Jerem