无法找到具体的ID - Android Java

时间:2016-11-05 09:23:53

标签: java android

你好我正在使用roughike Bottombar,我想用5个不同的Tab创建一个OnTabSelectedListener。目前它正在使用3个不同的选项卡但是当我想添加4或5选项卡时,我无法找到选项卡的特定ID。

我的代码现在看起来像这样:

 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="+@id/tBarAccount"
            title="Account" />

        <tab
            icon="@drawable/settings"
            id="+@id/tab_settings"
            title="Settings" />
    </tabs>

</resources>

如果我尝试运行代码,则会收到以下错误:

  

错误:(40,41)错误:找不到符号变量tBarAccount

我希望你们能帮助我

2 个答案:

答案 0 :(得分: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" />

答案 1 :(得分:1)

id="+@id/tBarAccount"更改为id="@+id/tBarAccount"

干杯