Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I put in 2 texts then pressed save and saving internal storage. Press List button reading List.java there are saving data's in list. so I pressed MainActivity button and i put in 2 texts again. But this time List.java's previous data has lost. Only one row data's in listview. How can i fix this problem. I want to dynamically add 2 items in internal storage in listview. How to save internal storage via custom adapter in android list

Thanks for help.

example app screenshot

share|improve this question
    
show your code... –  Achilles Jun 7 '13 at 4:56
    
    
why you are not using local database for that.?? –  Achilles Jun 7 '13 at 5:05
    
so i'm beginner –  user1303250 Jun 7 '13 at 5:06
    
ohkk.. then use local database for storing data and retriving it.. –  Achilles Jun 7 '13 at 5:07
show 3 more comments

2 Answers

Try to use Custom view for List row and implement that view into List View.

Here are some of the links for Custom List

share|improve this answer
    
i want add items to internal storage listview thx for advice. –  user1303250 Jun 7 '13 at 5:18
add comment

You could try saving the array list to Internal Storage as a file. Check this answer or code below,

For writing to file,

    try {
   //Modes: MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITABLE
   FileOutputStream output = openFileOutput("lines.txt",MODE_WORLD_READABLE);
   DataOutputStream dout = new DataOutputStream(output);
   dout.writeInt(text_lines.size()); // Save line count
   for(String line : text_lines) // Save lines
      dout.writeUTF(line);
   dout.flush(); // Flush stream ...
   dout.close(); // ... and close.
}
catch (IOException exc) { exc.printStackTrace(); }

For reading it,

    FileInputStream input = openFileInput("lines.txt"); // Open input stream
DataInputStream din = new DataInputStream(input);
int sz = din.readInt(); // Read line count
for (int i=0;i<sz;i++) { // Read lines
   String line = din.readUTF();
   text_lines.add(line);
}
din.close();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.