如何选择列表视图项并将我带到新页面?

时间:2014-06-27 13:20:09

标签: android listview

public void onListItemClick(ListView l, View v, int position, long id) 
        {

           // Do something when a list item is clicked
            if ( position == 5)
            {
                Intent myIntent = new Intent(Categories.this,Adventure.class);
                startActivity(myIntent);
            }


        }

如何选择列表视图项并将我带到新页面?

2 个答案:

答案 0 :(得分:-1)

您需要设置listiemClickListner(); 为活动类实施onListItemClick,然后

 ListView lv = (ListView)findViewById(R.Id.LV);
    lv.setOnListItemclickListner(this);

如果您需要,可以为每个列表视图设置列表器。

lv.setOnItemClickListener(new OnItemClickListener() {

    @Override
public void onItemClick(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {

            }
});

答案 1 :(得分:-1)

list.setOnItemClickListener(new OnItemClickListener() {

    @Override
public void onItemClick(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {
        if ( position == 5)
        {
            Intent myIntent = new Intent(Categories.this,Adventure.class);
            startActivity(myIntent);
        }
}
});