1

我制作了一个简单的列表,当单击 ListItem 时它会调用其他活动,但它对我不起作用。当我点击时,什么都没有出现。怎么了 ?这是代码:

    String classes[]={"StartingPoint","Splash", "ex1","ex2"};
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String cheese = classes[position];
    try
    {

        Class ourclass = Class.forName("com.alfred.splashscreenwithsound." + cheese);
        Intent myintent = new Intent(this,ourclass);
        startActivity(myintent);
    }
    catch(ClassNotFoundException e)
    {
        e.printStackTrace();
    }
}

}

4

1 回答 1

5

我认为你还没有实现 OnItemClickListener

试试下面的代码

        //Declare your listView  here
        yourlistView.setOnItemClickListener(new OnItemClickListener() {

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


                 Intent callActivity = new Intent(CurrentActivity.this,NextActivity.class); 
                 startActivity(callActivity);
                 }
            }); 
        }

希望能帮助到你

于 2012-08-02T12:39:13.043 回答