导航抽屉更新列表查看并避免崩溃

时间:2015-02-23 09:29:29

标签: android

任何人都可以告诉我为什么按下菜单按钮后抽屉布局会崩溃?

我的主要问题是关于更新listView?我可以添加字符串并将它们放在listView下,还是应该将菜单更改为framelayout并在其上添加按钮?

希望我的英语不坏!

修改

我现在遇到PlanetFragments的问题

/** Swaps fragments in the main content view */
    private void selectItem(int position) {
        // Create a new fragment and specify the planet to show based on position
        Fragment fragment = new PlanetFragment();
        Bundle args = new Bundle();
        args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
        fragment.setArguments(args);

        // Insert the fragment by replacing any existing fragment
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.content_frame, fragment)
                .commit();

        // Highlight the selected item, update the title, and close the drawer
        mDrawerList.setItemChecked(position, true);
        setTitle(mPlanetTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    }

PlanetFragment无法解决

崩溃的第一个问题是从这里

/** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mDrawerTitle);
        }

1 个答案:

答案 0 :(得分:1)

使用getSupportActionBar()

getSupportActionBar().setTitle(mDrawerTitle);