Im trying to fill a spinner in my application in a different thread. Can somoene tell me why the following code is not working?
The following code is in the oncreate() method
Thread asyn = new Thread(){
public void run(){
try{
int klok = 0;
while(klok < 5000){
sleep(100);
klok = klok + 100;
}
try{
String[] items = new String[] {"One", "Two", "Three"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Materiaal.this, android.R.layout.simple_spinner_item, items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter);
}catch(Exception ex){
ex.printStackTrace();
}finally{
//adapter.notifyDataSetChanged();
}
}catch(InterruptedException ex){
ex.printStackTrace();
}
}
};
asyn.start();
I think you should use the method runOnUiThread(Runnable r) from the Activity.
Maybe do something like this
I hope it helps..