Open different activities on each listview click

后端 未结 4 1069
春和景丽
春和景丽 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:40

    convertView = layoutInflater.inflate(R.layout.listview, parent, false);
    

    below it,add

    convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (position == 1){
                getActivity().startActivity(new Intent(MainActivity.this,secondActivity.class));
            }else if (position == 2){
                getActivity().startActivity(new Intent(MainActivity.this,secondActivity.class));
            }else if (position == 3){
                getActivity().startActivity(new Intent(MainActivity.this,secondActivity.class));
            }
        }
    });
    

提交回复
热议问题