How do i use the OnItemClickListener to start a new intent based on which item is clicked?

后端 未结 3 1997
孤街浪徒
孤街浪徒 2021-01-21 02:44

I want to be able to start a new activity using the Intent class. I know how to start an activity by using these lines of code:

Intent myIntent = new Intent(v.ge         


        
3条回答
  •  臣服心动
    2021-01-21 03:08

    @Override
        public void onItemClick(AdapterView parent, View view, int position, long id) {
        Intent intent = null;
        switch(position) {
        case 1:
                intent = new Intent(getApplicationContext(), Activity2.class);
                startActivity(intent);
        break;
        case 2:
               intent = new Intent(getApplicationContext(), Activity3.class);
               startActivity(intent);
               break;
        default:
        }
        }
    

    });

提交回复
热议问题