Search in sources :

Example 1 with DrawerListAdapter

use of com.szu.androidpractice.adapter.DrawerListAdapter in project AndroidPractice by lguipeng.

the class SlideMenuFragment method init.

private void init() {
    final List<String> list = new ArrayList<>();
    list.add("Spring");
    list.add("Summer");
    list.add("Autumn");
    list.add("Winter");
    DrawerListAdapter adapter = new DrawerListAdapter(getActivity(), list);
    mDrawerMenuListView.setAdapter(adapter);
    mDrawerMenuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mCurrentTitlePosition = position;
            mDrawerMenuListView.setItemChecked(position, true);
            mDrawerLayout.closeDrawer(parent);
        }
    });
    mDrawerMenuListView.setItemChecked(mCurrentTitlePosition, true);
    setTitle(list.get(mCurrentTitlePosition));
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, 0, 0) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            activity.invalidateOptionsMenu();
            setTitle(R.string.slide_menu);
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            activity.invalidateOptionsMenu();
            setTitle(list.get(mCurrentTitlePosition));
        }
    };
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.setScrimColor(getColor(R.color.window_background));
}
Also used : ArrayList(java.util.ArrayList) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) AdapterView(android.widget.AdapterView) DrawerListAdapter(com.szu.androidpractice.adapter.DrawerListAdapter) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Aggregations

ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 InjectView (butterknife.InjectView)1 DrawerListAdapter (com.szu.androidpractice.adapter.DrawerListAdapter)1 ArrayList (java.util.ArrayList)1