为什么我的导航抽屉是空的?

时间:2015-04-24 00:27:57

标签: android navigation-drawer

我正在复制/粘贴here中的示例,但是当我运行它时,我的抽屉完全是空的。例如,在运行setAdapter之后的下面的主要活动中,我的列表视图为空/ null。这是为什么?

public class MainActivity extends ActionBarActivity {

private String[] mPlanetTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private CharSequence mTitle;
private ActionBarDrawerToggle mDrawerToggle;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = "test";

    mPlanetTitles = new String[]{"one", "two", "three"};
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // Set the adapter for the list view
    mDrawerList.setAdapter(new ArrayAdapter<String>(this,
            R.layout.drawer_list_item, mPlanetTitles));
    // Set the list's click listener
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.drawable.ic_drawer,  /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open,  /* "open drawer" description */
            R.string.drawer_close  /* "close drawer" description */
    ) 

我还将所有getActionBar更改为getSupportActionBar

0 个答案:

没有答案