Android which button index from array was pressed

后端 未结 2 508
天命终不由人
天命终不由人 2021-02-10 17:57

How do I set up a OnClickListener to simply tell me which index button was pressed from an array of buttons. I can change text and color of these buttons using the array. I

2条回答
  •  广开言路
    2021-02-10 18:17

    You can set Tag value and get the Tag on Click:

    TButton[1] = (Button)findViewById(R.id.Button01);
    TButton[1].setTag(1);
    
    
    onClick(View v)
    {
      if(((Integer)v.getTag())==1)
      {
       //do something
      }
    }
    

提交回复
热议问题