2016-11-05 8 views
-3

こんにちは私はroughike Bottombarを使用しています。私は5つの異なるタブでOnTabSelectedListenerを作成したいと思います。現在は3つの異なるタブで動作していますが、4つまたは5つのタブを追加する場合は、タブのIDを特定できません。特定のIDを見つけることができません - Android Java

私のコードは今、この権利のようになります。

bbMainNavigation.setOnTabSelectListener(new OnTabSelectListener() { 
     @Override 
     public void onTabSelected(@IdRes int tabId) { 
      Fragment fMainContent = null; 

      if (tabId == R.id.tBarFriends) { 
       cMainFragment = FriendsFragment.class; 
      } else if (tabId == R.id.tBarMessage) { 
       cMainFragment = MessagesFragment.class; 
      } else if (tabId == R.id.tBarRadar) { 
       cMainFragment = RadarFragment.class; 
      } else if (tabId == R.id.tBarAccount){ 
       cMainFragment = AccountFragment.class; 
      } 

のタブを使用した私のXMLは以下のようになります。

<?xml version="1.0" encoding="utf-8"?> 

<resources> 

    <tabs> 

     <tab 
      icon="@drawable/friends" 
      id="@+id/tBarFriends" 
      title="Friends" /> 

     <tab 
      icon="@drawable/message" 
      id="@+id/tBarMessage" 
      title="Message" /> 

     <tab 
      icon="@drawable/radar" 
      id="@+id/tBarRadar" 
      title="Radar" /> 

     <tab 
      icon="@drawable/account" 
      id="[email protected]/tBarAccount" 
      title="Account" /> 

     <tab 
      icon="@drawable/settings" 
      id="[email protected]/tab_settings" 
      title="Settings" /> 
    </tabs> 

</resources> 

私がしようとした場合私はfollを取得するコードを実行するエラーのため:

Error:(40, 41) error: cannot find symbol variable tBarAccount

を、私はあなたたちは

+0

がものにXMLであなたの最後の二つの 'のid's比較私を助けることを願って上記。あなたは '+'と '@'のswapped - 'id =" + @ id/tBarAccount "を得ました。 –

答えて

2
<tab 
     icon="@drawable/account" 
     id="@+id/tBarAccount"   <<'+' must be after '@' 
     title="Account" /> 

    <tab 
     icon="@drawable/settings" 
     id="@+id/tab_settings"  <<'+' must be after '@' 
     title="Settings" /> 
+0

感謝の男私はそれを見落とした:D – user5985727

関連する問題