1. Are you ready for the Galaxy S20? Here is everything we know so far!

Reading from file

Discussion in 'Android Development' started by WillDot, May 17, 2011.

  1. WillDot

    WillDot Lurker
    Thread Starter

    Hey guys.

    I have to hand in my application for my uni project on Thursday and I have come across a problem.

    I need to be able to save the string value from an "editText" when I click on the save button. Then when I re-open the application, the "editText" will automatically retrieve the save file.

    I have got the following code so far.

    Code (Text):
    1. public class AppMain extends Activity {
    2.    
    3.     TextView textOut;
    4.     EditText getInputMain;
    5.     String textOutput = textOut.getText().toString();
    6.  
    7.     @Override
    8.     public void onCreate(Bundle savedInstanceState){
    9.         super.onCreate(savedInstanceState);
    10.         setContentView(R.layout.main_large);
    11.        
    12.  
    13.         FileInputStream fis =openFileInput(textOutput);
    14.         ObjectInputStream ois = new ObjectInputStream(fis);
    15.         flow f = (Flow) ois.readObject();
    16.        
    17.         //Save button
    18.        
    19.         textOut= (TextView)findViewById(R.id.input);
    20.         textOut = (EditText) findViewById(R.id.input);
    21.         Button saveButton = (Button) findViewById(R.id.saveButton);
    22.         saveButton.setOnClickListener(new OnClickListener(){
    23.            
    24.             public void onClick(View v){
    25.                 textOut.toString();
    26.                
    27.                 //closing the keyboard
    28.                 InputMethodManager imm =(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    29.                 imm.hideSoftInputFromWindow(textOut.getWindowToken(),0);
    30.                
    31.                 //saving to sd card
    32.            
    33.                 FileOutputStream fos = openFileOutput(textOutput,Context.MODE_PRIVATE);
    34.                 ObjectOutputStream oos = new ObjectOutputStream(fos);
    35.                 oos.writeObject(textOut); oos.close();
    36.                
    37.                                        
    38.                                         }
    39.                                                             });
    A) Is the write to file bit correct?
    B) The part where I read from file says that "flow" isn't acceptable. What am I doing wrong?

    Cheers guys. I really need help to get this finished by Thursday :eek:
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Reading file
  1. nickdalzell
    Replies:
    1
    Views:
    515
  2. casjkent2
    Replies:
    1
    Views:
    574
  3. sachertorte
    Replies:
    6
    Views:
    745
  4. marc kirk
    Replies:
    15
    Views:
    1,144
  5. kayakkielbasa
    Replies:
    8
    Views:
    1,276
  6. Ecoermobile123
    Replies:
    0
    Views:
    805
  7. shakushinnen
    Replies:
    8
    Views:
    2,109
  8. regressist
    Replies:
    11
    Views:
    1,083
  9. Biffos
    Replies:
    4
    Views:
    1,095
  10. Richard Linder
    Replies:
    3
    Views:
    1,752

Share This Page

Loading...