0

我想在列表视图中单击项目时打开一个新活动。这个怎么做。?这是代码:

package com.example.c_progams;

公共类 Second_listview 扩展 ListActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.second_listview);

    setListAdapter (new ArrayAdapter<String>(this, R.layout.second_listview, type));
    ListView list = getListView();
    list.setTextFilterEnabled(true);
    list.setOnItemClickListener(new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub


        }



    });
}

静态最终字符串 [] 类型 = 新字符串 []{

"Array", "Operator Overloading", "Inheritence", "Strings", "Pointers", "Files", "Misclaneous" 

};

}

4

2 回答 2

0

只需将您的 Activity 调用代码放入 onItemClick(..) 方法

像这样:

 @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub

            Intent nextScreen = new Intent(getApplicationContext(), nextScreenActivity.class);
            startActivity(nextScreen);

        }
于 2013-01-17T20:12:58.980 回答
0
public void onListItemClick(ListView lv, View v, int position, long id) {
    Intent intent;
    switch (position) {
        case 0:
            intent = new Intent(this, FirstActivity.class);
            break;
        case 1:
            intent = new Intent(this, SecondActivity.class);
            break;
        default:
            break;
    }


    startActivity(intent);
}
于 2013-01-17T20:11:05.707 回答