Domanda

I have a TabActivity which loads 2 ListActivity in 2 Tabs. When I click on a list item in either of the ListActivity, I want to pass this value back to the TabActivity. What's the best way to do this? I'm thinking of using a BroadcastReceiver. Any thoughts?

È stato utile?

Soluzione 4

Agree with Javanator. I did it the BroadcastReceiver way and it works. Tedious but it works.

Altri suggerimenti

consider this illustration

public class MyTabActivity extends TabActivity
{
      public void onCreate(Bundle b)
      {
            //implementation
      }
      public void setSomeObject(Object someOjbect)
      {
                //will get an object and act accordinglt
      }
}

and in any of your child Activity you would use to set Object like this way:

MyTabActivity myTabParent = (MyTabActivity)this.getParent();
myTabParent.setSomeObject(anyObject);

Pass values using intent.

Bundle b=new Bundle();
Intent i=new Intent(this, AnotherActivity.class);
b.putDouble("data", datavalue);//putting the datavalue
i.putExtras(b);

And receive values in AnotherActivity as

double value =  this.getIntent().getDoubleExtra("data", defaultvalue);

Inter Change the lines for both activity and get data from each other.

Still Tab-activity is deprecated.I suggest you to please use Fragments instead of this class and it's provide all your requirements., You can use the v4 support library for these purpose. Thank You

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top