0

错误发生在 /* // UserProfile navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));*/ // 付款 navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1))); // 邀请好友 navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1))); // 帮助 navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));

    //Trip History

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[7], navMenuIcons.getResourceId(7, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[8], navMenuIcons.getResourceId(8, -1)));

这是我的完整代码:@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_navigation_drawer, container, false); mDrawerListView = (ListView) rootView.findViewById(R.id.listViewDrawer); mToolbar = ((NavigationActivity) getActivity()).getToolbar();

/*  mDrawerListView = (ListView) inflater.inflate(
            R.layout.fragment_navigation_drawer, container, false);*/

    // load slide menu items
    String[] navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

    // nav drawer icons from resources
    TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);


    mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);

    ArrayList<NavDrawerItem> navDrawerItems = new ArrayList<NavDrawerItem>();

    // adding nav drawer items to array
    // Home
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));

/* // UserProfile navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));*/ // 支付 navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId( 1, -1))); // 邀请好友 navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1))); // 帮助 navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));

    //Trip History

    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[7], navMenuIcons.getResourceId(7, -1)));
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[8], navMenuIcons.getResourceId(8, -1)));

//驱动模式开/关

    // Recycle the typed array
    navMenuIcons.recycle();

    // setting the nav drawer list adapter
    adapter = new NavDrawerListAdapter(getActivity(),
            navDrawerItems);

    mDrawerListView.setAdapter(adapter);

    mDrawerListView
            .setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    selectItem(position);
                    adapter.setSelectedItem(position);
                }
            });


    // Select either the default item (0) or the last selected item.
    selectItem(mCurrentSelectedPosition);
    adapter.setSelectedItem(mCurrentSelectedPosition);

    return rootView;
}
4

1 回答 1

0

试试这个(为我工作)

  • 将此行添加到您的 build.gradle 文件

安卓 {

  lintOptions {
     disable "ResourceType"} 

}

于 2017-10-12T11:41:36.387 回答