Saturday, 15 March 2014

android - Keep ListView items between activities -


All,

I looked around and searched on stackoverflow, but did not answer my question Was or was I just wrongly divorced

I have a list view that displays text with the button when this button is clicked, then I am opening another activity with a separate list from the previous activity.

Now, when I press the "back" button, I am going back to "Activity 1". Here I can press again on the same line or the second button and I should go to "Activity 2" which should be placed in the first "listview_Activity2" text and add the newly selected selected text from "listview_Activity1". / P>

I have created a custom adapter for both list views and the "Activity 1" works well on the first button press, however, the app does not retain the selected text on the second press.

Now, everywhere I see either the item is being added to either by pressing a button or viewing the item with the same activity state. I do not care about item status, and my items are coming from some other activity.

Can anyone help please?

Here is the code:

  Private static list & gt; Products & gt; Products; Override public null on @reate (bundle saved instance) {super.onCreate (saved instance); Products = new arrelisted & lt; Products & gt; (); Intent = getIntent (); Product product = intent.getableextra ("cart_product"); Products.add (product); CartLineAdapter Adapter = New CartLineAdapter (this, R.layout.cart_line, product); SetContentView (R.layout.cart); See List View = (List View) SearchVBIID (RID.art_items); View.setAdapter (adapter); }   

You need to have some perseverance for your data. If you want to keep it in the app, you can use the Static variable to create a class, which contains Static Arrayist or something that you would like to do first for After selecting an item from the list in Activity , we will add the data. Then every time you go to the second activity , you can populate your list using that data from that Fixed Arrayist.

Your other options are to store it in the shared context data (possibly not ideal for this situation but may be) or DB Continue if you want this application to close.

Edit

For any of the options, backpacks ()

  Can override. // Save data here if it has not been super saved yet. Backdrop (); }   



No comments:

Post a Comment