I'm trying to use the code in this excellent post but Android keeps crashing. What I want:
1) Download a file at the start
2) A spinner is populated with the contents of the file downloaded
Here's the code:
Using java Syntax Highlighting
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- progressDialog = ProgressDialog.show(DownloadFile.this, "", "Loading, please wait...");
- new Thread() {
- public void run() {
- try{
- reader=readURL("http://domain.net/spinner.txt"); // Download the file
- } catch (Exception e) { }
- // dismiss the progress dialog
- progressDialog.dismiss();
- // Change the spinner values with the downloaded values
- spinner1 = (Spinner) findViewById(R.id.Spinner01);
- spinner1.setPrompt("Values:");
- ArrayAdapter adapter=new ArrayAdapter(DownloadFile.this,android.R.layout.simple_spinner_dropdown_item);
- // populate spinner
- try {
- while ((line = reader.readLine()) != null) adapter.add(line);
- } catch (IOException e) { }
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- spinner1.setAdapter(adapter);
- }
- }.start();
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
The application crashes after trying to change the spinner content. Is it not possible to change UI inside a Thread()?
Thanks in advance!




