Open different activities on each listview click

后端 未结 4 1068
春和景丽
春和景丽 2021-01-27 07:18

I am having problem setting OnClickListener to my listview. I want to open different activities when different listview item is being clicked. But i am not able to get it done.

4条回答
  •  孤城傲影
    2021-01-27 07:51

    I don't see where you set an OnClickListener for your View though. Inside of your ListAdapter's getView(), you should do

    View v = super.getView(position, convertView, parent);
    
    if(v != null) {
        v.setOnClickListener(new View.OnClickListener() {
            Intent intent = new Intent(YourContext, ActivityToStart.class);
            startActivity(intent);
        });
    }
    

    I hope that helps.

提交回复
热议问题