2016-01-27 4 views
1

Je suis en train d'actualiser chaque onglet hôte en cliquant sur, j'ai essayé d'utiliser addFlags(), mais je ne reçois pas cette méthode.TabHost addFlags() introuvable dans FragmentTabHost

Veuillez vérifier mon code. J'utilise FragmentTabHost. Est-il possible d'utiliser la méthode addFlags() dans FragmentTabHost.

public class HomeParentFragement extends FragmentActivity implements  View.OnClickListener { 

private static final String TAB_1_TAG = "tab_1"; 
private static final String TAB_2_TAG = "tab_2"; 
private static final String TAB_3_TAG = "tab_3"; 
private static final String TAB_4_TAG = "tab_4"; 
private static final String TAB_5_TAG = "tab_5"; 
private FragmentTabHost mTabHost; 
View view; 
Activity mActivity; 
private float startX; 
ImageButton btn_sidemenu; 
Context mContext; 
private LinearLayout ll, ll_profile, ll_sidemenu_wallet, ll_sidemenu_postjob, ll_howitwork, ll_help, ll_logout; 
/** 
* ATTENTION: This was auto-generated to implement the App Indexing API. 
* See https://g.co/AppIndexing/AndroidStudio for more information. 
*/ 
private GoogleApiClient client; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.bottam_layout); 
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); 
    mContext = this; 
    mActivity = this; 
    btn_sidemenu = (ImageButton) findViewById(R.id.ibtn_sidemenu); 
    mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); 
    ll = (LinearLayout) findViewById(R.id.slider); 
    ll_profile = (LinearLayout) findViewById(R.id.ll_sidemenu_profile); 
    ll_sidemenu_wallet = (LinearLayout) findViewById(R.id.ll_sidemenu_wallet); 
    ll_sidemenu_postjob = (LinearLayout) findViewById(R.id.ll_sidemenu_postJob); 
    ll_howitwork = (LinearLayout) findViewById(R.id.ll_sidemenu_howitwork); 
    ll_help = (LinearLayout) findViewById(R.id.ll_sidemenu_help); 
    ll_logout = (LinearLayout) findViewById(R.id.ll_sidemenu_logout); 
    ll.setVisibility(View.GONE); 
    btn_sidemenu.setOnClickListener(this); 
    ll_profile.setOnClickListener(this); 
    ll_sidemenu_wallet.setOnClickListener(this); 
    ll_sidemenu_postjob.setOnClickListener(this); 
    ll_howitwork.setOnClickListener(this); 
    ll_help.setOnClickListener(this); 
    ll_logout.setOnClickListener(this); 
    mTabHost.getTabWidget().setDividerDrawable(null); 

    mTabHost.invalidate(); 
    mTabHost.addTab(
      mTabHost.newTabSpec(TAB_1_TAG).setIndicator(getTabIndicator(mTabHost.getContext(), "", getResources().getDrawable(R.drawable.home_tab_1))), 
      HomeTabAdvanceSearchFragments.class, null); 
    mTabHost.addTab(
      mTabHost.newTabSpec(TAB_2_TAG).setIndicator(getTabIndicator(mTabHost.getContext(), "", getResources().getDrawable(R.drawable.home_tab_2))), 
      HomeTabFavouriteFragment.class, null); 
    mTabHost.addTab(
      mTabHost.newTabSpec(TAB_3_TAG).setIndicator("", getResources().getDrawable(R.drawable.hometab3_normal)), 
      HomeTabBasicSearchFragment.class, null); 
    mTabHost.addTab(
      mTabHost.newTabSpec(TAB_4_TAG).setIndicator(getTabIndicator(mTabHost.getContext(), "", getResources().getDrawable(R.drawable.home_tab_4))), 
      HomeTabMessageFragment.class, null); 
    mTabHost.addTab(
      mTabHost.newTabSpec(TAB_5_TAG).setIndicator(getTabIndicator(mTabHost.getContext(), "", getResources().getDrawable(R.drawable.home_tab_5))), 
      ListJobParentFragment.class, null); 


    // Inflating color for the first time. 
    for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { 
     mTabHost.getTabWidget().getChildAt(i) 
       .setBackgroundColor(Color.parseColor("#FFFFFF")); 
    } 

    mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()) 
      .setBackgroundColor(Color.parseColor("#FFFFFF")); 
    // ============== End of color inflation ================== 

    mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { 

     @Override 
     public void onTabChanged(String tabId) { 
      ll.setVisibility(View.GONE); 

      // Inflating color when tab is selected. 
      for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { 
       mTabHost.getTabWidget().getChildAt(i) 
         .setBackgroundColor(Color.parseColor("#FFFFFF")); 
      } 

      mTabHost.getTabWidget().getChildAt(mTabHost.getCurrentTab()) 
        .setBackgroundColor(Color.parseColor("#FFFFFF")); 
      // ============== End of color inflation ================== 

     } 
    }); 

    for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { 
     final TextView tv = (TextView) mTabHost.getTabWidget() 
       .getChildAt(i).findViewById(android.R.id.title); 

     if (tv == null) 
      continue; 
     else 
      tv.setTextSize(8); 

    } 


    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
} 

private View getTabIndicator(Context context, String string, Drawable drawable) { 
    View view = LayoutInflater.from(context).inflate(R.layout.tab_layout, null); 
    ImageView iv = (ImageView) view.findViewById(R.id.imageViewTabView); 
    iv.setImageDrawable(drawable); 

    return view; 
} 

@Override 
public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.ibtn_sidemenu: 
      ll.setVisibility(View.VISIBLE); 

      break; 
     case R.id.ll_sidemenu_profile: 
      ll.setVisibility(View.GONE); 

      Fragment newFragment = new SideMenuParentFragment(); 
      android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
      transaction.replace(android.R.id.tabcontent, newFragment); 
      transaction.addToBackStack(null); 
      transaction.commit(); 

      break; 
     case R.id.ll_sidemenu_wallet: 
      ll.setVisibility(View.GONE); 

      break; 

     case R.id.ll_sidemenu_postJob: 
      ll.setVisibility(View.GONE); 
      Fragment newFragmentPostJob = new PostJobParentFRagment(); 
      android.support.v4.app.FragmentTransaction transactionPostJob = getSupportFragmentManager().beginTransaction(); 
      transactionPostJob.replace(android.R.id.tabcontent, newFragmentPostJob); 
      transactionPostJob.addToBackStack(null); 
      transactionPostJob.commit(); 


      break; 
     case R.id.ll_sidemenu_howitwork: 
      ll.setVisibility(View.GONE); 

      break; 
     case R.id.ll_sidemenu_help: 
      ll.setVisibility(View.GONE); 

      break; 
     case R.id.ll_sidemenu_logout: 
      ll.setVisibility(View.GONE); 
      Utils.removeSharedPreferences(mContext, "group_id"); 
      Intent i = new Intent(getApplicationContext(), MenuActivity.class); 
      startActivity(i); 
      finish(); 

      break; 
    } 


} 



@Override 
public void onBackPressed() { 
    Utils.exitApp(mActivity); 

} 

} 

Répondre

0
tabHost.addTab(tabHost.newTabSpec("tab2") 
    .setIndicator("Second Text") 
    .setContent(
     new Intent(this, class2.class) 
      .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) 
    )); 

Ceci est mon code de travail à ma fin:

mTabHost.addTab(
       mTabHost.newTabSpec(TAB_1_TAG).setIndicator(getTabIndicator(mTabHost.getContext(), "", getResources().getDrawable(R.drawable.home_tab_1))), 
       HomeTabAdvanceSearchFragments.class, null).setContent(new Intent(this, class2.class) 
         .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) 
     )); 
+0

désolé, il ne fonctionne pas. affiche une erreur Android Exception: Avez-vous oublié d'appeler 'public void setup (LocalActivityManager activityGroup)' – DKV

+0

après le code complet afin d'aider de meilleure façon. –

+0

S'il vous plaît vérifier mon code mis à jour – DKV