简体   繁体   中英

Starting Activities on different tabs

In Activity A, I have 3 ImageView which call a function that starts Activity B. Activity B has 3 tabs. What's a way to correlate which tab Activity B starts with the ImageView? For example, if I push ImageView 2, I want the second tab to be shown when Activity B starts.

I know I can pass values between activities like so:

 Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
 intent.putExtra("EXTRA_SESSION_ID", sessionId);
 startActivity(intent)

But how do I correlate the ImageView from the XML to a specific tab I want to start in another activity?

Just put a different code on each of your ImageView (ImageButon might be a better choice to consider BTW ;-) )

Intent intent = new Intent(getBaseContext(), ActivityB.class);
 intent.putExtra("TABTODISPLAY", 1);// or 2, or 3
 startActivity(intent)

And then you can just do a switch of this number in ActivityB

I don't understand what's your problem and which step is giving you problem

If you are afraid of hardcoded numbers, there are many ways to achieve it..

1) You can use the tag property of the Image

2) You can use the onClick property of the ImageButton and switch the view name

3) You could use the onClickListener

etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM