Selecting a Tab activity two ways
My app has three tabs, A, B, C that have three distinct activities.
Tab A includes a list view. User can either select Tab B or scroll the list view in A, selecting a row will take him to Tab B with the position of the selected row.
How can I detect in Tab B that the user has selected a row or clicked on Tab B. Clicking on Tab B selects a default, whereas select开发者_Python百科ing a row in A makes B do something special with the data. I could create a separate activity that is launched when a row is selected, but that is code duplication and I prefer trying to find out if B can detect how it was launched.
Use the Extras attribute of the Intent you use to launch tab B's Activity.
eg.
When you launch Tab B from a list click:
Intent tabBIntent = new Intent(this, TabB.class);
tabBIntent.putExtra("fromList", true);
startActivity(tabBIntent);
in TabB's onCreate (or somewhere similar):
if (getIntent().getBooleanExtra("fromList", false))
....
精彩评论