点击列表视图后,我的应用程序崩溃了

时间:2015-04-10 11:41:57

标签: android listview

点击ListView时,我的应用崩溃了:

public class MainActivity extends ActionBarActivity implements AdapterView.OnItemClickListener{
    private Toolbar toolbar;
    private ListView listview;
    private NavDrawerAdapter navDrawerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar= (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setUp(R.id.fragment_navigation_drawer,(DrawerLayout) findViewById(R.id.drawer_layout),toolbar);
        listview= (ListView) findViewById(R.id.drawerList);
        navDrawerAdapter= new NavDrawerAdapter(this);
        listview.setAdapter(navDrawerAdapter);
        listview.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if(position==0){
        Intent intent = new Intent(this,login.class);
        startActivity(intent);
    }

    selectedItem(position);
}

1 个答案:

答案 0 :(得分:-1)

      @Override public void onItemClick(AdapterView parent, View view, int position, long id) {

       if(position==0){ 
            Intent intent = new Intent(MainActivity.this,login.class);
            startActivity(intent);
       } 

       selectedItem(position); 
      }

启动活动的参数错误。但仍然使用该代码,编译器不应该允许你。 是崩溃还是编译错误?