Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Activities in the tab can be switched in the following manner.</p> <p>First Let us understand the flow:</p> <ol> <li><p>We have in a Tab host , activity (say a list) from which we need to go to the next Activity (say details for the clicked item) under the same tab. For this we can use the concept of replacing the activity.Also setting the flags for the tab selected and other for knowing that details are being shown now</p></li> <li><p>When we press back we should get the previous activity under the same tab.For this instead of again replacing the activity we can refresh the tab while using the particular flag for tab which was selected. Also if flag for show details is true we'll go the the list in the same tab or else we will go the activity before the tabwidget (normal use of onBackPressed)</p></li> </ol> <p>The code can be as follows..</p> <ol> <li>For going from list to details...</li> </ol> <p>(This can be in the onClickListener)</p> <pre><code>private OnClickListener textListener = new OnClickListener() { @Override public void onClick(View v) { Constants.SHOW_DETAILS = true; Intent intent = new Intent(context, DetailsActivity.class); replaceContentView("activity3", intent); } }; public void replaceContentView(String id, Intent newIntent) { View view = ((ActivityGroup) context) .getLocalActivityManager() .startActivity(id, newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView(); ((Activity) context).setContentView(view); } </code></pre> <ol> <li><p>When back pressed is done we override on BackPressed in each of the Activity under the tab to go to the list again from the details screen</p> <pre><code>@Override public void onBackPressed() { // TODO Auto-generated method stub super.onBackPressed(); if (MathHelper.SHOW_DETAILS) { Log.e("back", "pressed accepted"); Constants.LIST_ACTIVITY = 1; Constants.SHOW_DETAILS = false; Intent intent = new Intent(this, Tab_widget.class); startActivity(intent); finish(); } } </code></pre></li> </ol> <p>The most important part here is Constants.LIST_ACTIVITY = 1; it indicates which tab we are in. so the corresponding activities will have its value as 0,1,2...etc</p> <p>Again to load the correct list (Activty) when the tab activity is refreshed we have to include this in the TabWidget onCreate after the creation of the tabs</p> <pre><code>tabHost.setCurrentTab(Constants.LIST_ACTIVITY); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload