populating a spinner from a text file

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

populating a spinner from a text file

Postby nuggetgtr » Mon Jan 12, 2009 5:19 am

Hi All,

This is a two part problem,
first part is how can i populate a spinner from a set amount of values and custom ones located in a text file?

I am using this code, I have thrown it together hoping it would work but it doesnt well the first part does hope someone can point me in the write direction, this is the code I have
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. private void populatespinner(){
  2.  
  3.                 ArrayAdapter<String> aa=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, items);
  4.  
  5.                 aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  6.  
  7.                 spin.setAdapter(aa);
  8.  
  9.                
  10.  
  11.                 ArrayAdapter<String> saa=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spentonitems);
  12.  
  13.                 saa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  14.  
  15.                 spentonspin.setAdapter(saa);
  16.  
  17.                
  18.  
  19.                 try {
  20.  
  21.                         InputStream in = openFileInput("spenton1.txt");
  22.  
  23.                        
  24.  
  25.                         if (in!=null) {
  26.  
  27.                                 BufferedReader reader=new BufferedReader(new InputStreamReader(in));
  28.  
  29.                                 String temp;
  30.  
  31.                                 StringBuffer buf=new StringBuffer();
  32.  
  33.                                 while ((temp = reader.readLine()) != null) {
  34.  
  35.                                         saa.add(temp);
  36.  
  37.                                         Toast
  38.  
  39.                                         .makeText(this, temp, 2000)
  40.  
  41.                                         .show();
  42.  
  43.                                 }
  44.  
  45.                                 in.close();
  46.  
  47.                         }
  48.  
  49.                 }
  50.  
  51.                 catch (Throwable ioe) {
  52.  
  53.                        
  54.  
  55.                 }
  56.  
  57.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


the second part is how to add said spinner items to a text file each on a new line
the code I has works but it appends to the end of the line not on a new line.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         addbtn.setOnClickListener(new View.OnClickListener() {
  2.  
  3.                
  4.  
  5.                 public void onClick(View view) {
  6.  
  7.                         String sov = new String(spenton.getText().toString());
  8.  
  9.                
  10.  
  11.         try {
  12.  
  13.                 OutputStreamWriter out = new OutputStreamWriter(openFileOutput("spenton1.txt",MODE_APPEND));
  14.  
  15.  
  16.  
  17.                 out.write(sov +"\n");
  18.  
  19.                 out.close();
  20.  
  21.         }
  22.  
  23.         catch (Throwable t) {
  24.  
  25.                
  26.  
  27.         }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


any ideas??

Thanks heaps
nuggetgtr
Freshman
Freshman
 
Posts: 5
Joined: Tue Jan 06, 2009 3:14 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 6 guests