views:

72

answers:

2

Hello.

I currently have a tab layout with 2 tabs, one tab with a list view and one with the option make strings so I can add them in the list view. Both tabs have their own activity because this made the code much more structured, and I dont have to repeat my self later.

Lets say im in the tab that offer me to create an string, and i press the update list button, how do I update the list view without startActivity()? If i use startActivity(), it starts List.java, and instead of displaying the list in the list view tab, it takes full screen, which defies the purpose of the tab view. In other words, the startActivity() steals the focus from the tab view of the list, and sends it fulscreen.

Thanks for your time.

Edit: I want to update the activity in my list view tab, without starting a new activity that goes to fullscreen, and doesnt update the one in the tab.

A: 

I had the same problem when i was making my app and the only solution i found was to add this flag to my intent so every time i go to the tab it would refresh it self

.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)

I hope it helps.

mklfarha
@Mayra i think that, what you are saying is true and it was what i was doing it, but how do you get your view to get updated effectively, because i had the data updated but it wouldn't show up, until i added this flag do you have any suggestions? i tried reloading my adapter, and invalidating it, etc...
mklfarha
+2  A: 

One solution is to have your data model separate from your view (Activity), this is good practice in general, but in this case allows your two tabs to interact with the same model.

You could provide access to the data model in your Application class. Then, when onResume is called on your list activity you can update the view based on the current data.

edit:

public class MyApplication extends Application {
   private List<MyObject> myData;

   public List<MyObject> getMyData() {
     return myData; 
   }

   public void setMyData(List<MyObject> mydata) {
     this.myData = myData;
   }
}

In your manifest you need to add the application tag to specify that it should use MyApplication as the application class.

Then, in your activity:

   public void onResume() {
      MyApplication app = (MyApplication) getApplication();
      List<MyData> data = app.getMyData();
      // update  my view with the data
   }
Mayra
Could you give me an example? I'm not sure I get quite get it. I'm kinda new to programming, been at it for 1 1/2 years.
lands
See edit for more details.
Mayra
Thanks, ill try it, had to change things around anyway.
lands