2016-06-18 17 views
0

このダイアログボックスから、基本的に私は&削除タブを追加するために私のプログラムを実施しているが、私の問題は、私はタブかどうかを確認する方法を見つけることができないで、私はそうTABSTabLayoutでタブがすでに削除されているかどうかを確認する方法? MainActivityの下

 tab1 = tabLayout.newTab().setText("TAB 1"); 
     tabLayout.addTab(tab1); 

     tab2 = (tabLayout.newTab().setText("TAB 2")); 
     tabLayout.addTab(tab2); 

を追加してい方法です私は私のアプリでこれを使用していたタブは、すでに以前

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (resultCode != RESULT_OK || data == null) 
    return; 
    settingList = (ArrayList <SettingCheckBox>) data.getSerializableExtra(SETTING_CHECK_BOX); 
    for (int i = 0; i < settingList.size(); i++) { 
    if (settingList.get(i).getChecked()) { 
    Log.d("**Checked Item**", String.valueOf(settingList.get(i).getDescription())); 
    //gets the description of the tab that is to be removed 
    String removeTab = String.valueOf(settingList.get(i).getDescription()); 
    //gets the value of the check box         
    Boolean checkedValue = settingList.get(i).getChecked(); 


    if (removeTab.equals("TAB 1")) { 
     //How to check if Tab is already removed ? 
     if (checkedvalue) 
     if (tabLayout.equals(tab1)) { 
     tabLayout.removeTab(tab1); 
     //basically removes fragment associated with the tab 
     pagerAdapter.removeTab(0, tab1); 
     } 
    } 

    } else if (removeTab.equals("TAB 2")) { 
    if (checkedValue) { 
     tabLayout.removeTab(tab2); 
     pagerAdapter.removeTab(1, tab2); 

    } 
    } 
    } 

答えて

0

を削除している場合は、すでにので、削除され、私のプログラムはエラーに実行されます。

public boolean isMatching(final String tabString){ 
    boolean match=false; 
    for(int i=0;i<tablayout.getTabCount();i++){ 
     if(tablayout.getTabAt(i).getText().toString().equals(tabString)){ 
      match=true; 
     } 
    } 
    return match; 
} 

次に、使用して:あなたは

if(isMatching(yourstring)){ 
    //you didnt removed it, 
    // there is at least one tab that equals your string 
}else{ 
    //there is no tab that matches your string 
} 

のように試してみて、再び来ることができますか?

+0

はい。高すぎる。 Btw私はこれについてもっと学ぶことができるソースを知っていますか? – choman

+1

@chomanはい、材料ガイドラインチェックアウトこのサイト:[タブレイアウトガイドライン](https://material.google.com/components/tabs.html#tabs-specs)、タブレイアウト、パラメータ、関数などについて学ぶ: TabLayout](https://developer.android.com/reference/android/support/design/widget/TabLayout.html)。 codepathsのガイドもご覧ください:[Codepath Tablayout](https://github.com/codepath/android_guides/wiki/Google-Play-Style-Tabs-using-TabLayout) –

+0

ありがとうございました。 :) – choman

関連する問題