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

后端 未结 3 2029
孤街浪徒
孤街浪徒 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:03

    Code which demonstrates single OnItemClick Listner for Multiple Buttons

    You can use the same for what u call as items!

    // On Click Listener for all 6 buttons

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        //int clickedButtonIs;
    
        if (v == button1)
        {
            // call intent 1;
        }
        else if (v == button2)
        {
            // call intent 2;
        }
        else if (v == button3)
        {
            // call intent 3;
        }
        else if (v == button4)
        {
            // call intent 4;
        }
        else if (v == button5)
        {
            // call intent 5;
        }
        else if (v == button6)
        {
            // call intent 6;
        }
    }
    

提交回复
热议问题