Designing chess in android

后端 未结 1 579
说谎
说谎 2021-01-29 08:13

I designed a user interface for a chess game by using buttons in a table layout. For the chess pieces I took the ASCII values and printed on the button as a string value. But I

1条回答
  •  野性不改
    2021-01-29 09:04

    If you just want the text value of the button, attach the following OnClickListener to all of your buttons:

    OnClickListener myButtonClickListener = new OnClickListener() { 
            @Override
            public void onClick(View v) {
                String buttonText = ((Button) v).getText();
                                //Do whatever you want with buttonText
    
            }
        };
    

    To assign it for the Button instance "myButton":

    myButton.setOnClickListener(myButtonClickListener );
    

    0 讨论(0)
提交回复
热议问题