开发者

Serializable an arrayList and Save it and to Read it

开发者 https://www.devze.com 2023-02-21 01:44 出处:网络
I am trying to save a arrayList permanently each time when i click on the button the function will add the new arrayList in the Memory so when will read it in another activityi will read all the array

I am trying to save a arrayList permanently each time when i click on the button the function will add the new arrayList in the Memory so when will read it in another activity i will read all the arrayList that been save and like that i will be able to keep my data even when i switch off the app and i will save all the history of the data been chosen by a click.

This Activity is the one i will like to 开发者_如何学Pythonsave the data from each time that the item been choose in the List by click

and to save it in the memory and to be able read this data in another activity to be show that in a List

public class ResultView extends Activity 
{
protected static final String LOG_TAG = null;
protected static final String EXTRA_BUTTONTEXT = null;
protected static final int RECEIVE_MESSAGE = 0;

String[] lv_arr = {};
TextView title,sum;
ListAdapter adapter;
TextView t;
private ListView lvUsers;
private ArrayList<Medicaments> mListUsers;
String responce=null;
protected int count;

private int FROMcountryChooseId,TOcountryChooseId;
CharSequence meToConvert;
private CharSequence nameOfFromcountry,nameOfTocountry;


ArrayList<History> results = new ArrayList<History>();

public void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.result); 


  //set the List of the product to the ListView
  mListUsers = getMedicamentsView();
  lvUsers = (ListView) findViewById(R.id.resultListView);
  lvUsers.setAdapter(new ListAdapter(this, R.id.resultListView, mListUsers)); 

  lvUsers.setOnItemClickListener(new OnItemClickListener()
  {

      private Object myObject;

    public void onItemClick(AdapterView<?> parent, View view,int position, long id)
      {




          Intent pingIntent = new Intent(getApplicationContext(),ConvertedView.class);

          //get the data from the listView in the right position
          int DCIN=mListUsers.get(position).DCIN;
          String molecule=mListUsers.get(position).DCI;
          String pathologie=mListUsers.get(position).Pathologie;
          String medicaments=mListUsers.get(position).Medicaments;

          //use pingIntent to share the data for the next Acitity
          pingIntent.putExtra("DCINChoosenMedicaments",DCIN);
          pingIntent.putExtra("moleculeChoosenMedicaments",molecule);
          pingIntent.putExtra("pathologieChoosenMedicaments",pathologie);
          pingIntent.putExtra("TOcountryChooseId",TOcountryChooseId);

          pingIntent.putExtra("nOfTocountry",nameOfTocountry);
           Log.i("Name of medicaments from ResultView **********************     "," "+nameOfTocountry);

           myObject=medicaments;

           //TODO:Save Data in the memory or or file 



           setResult(Activity.RESULT_OK,pingIntent);


          startActivity(pingIntent);
          //finish();




      }
   });



}

I try to look on the web to fine a good explanation but nothing that could help me i am really lost on this subject i will appreciate Help

Thank you Very much


Android serializable is not different than Java serializable. You can have all your doubts cleared by reading about it in Java docs here http://java.sun.com/developer/technicalArticles/Programming/serialization/ http://docs.oracle.com/javase/6/docs/technotes/guides/serialization/index.html

Hope this helps.


So do you need a persistent storage? If so, take a look at SharedPreferences or consider creating your own SQLite Database.


you can use serializtion to store ArrayList object into file as sequence of bytes.Then store file on sdcard

0

精彩评论

暂无评论...
验证码 换一张
取 消