Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は64個のボタンを作成したチェスをデザインしています。チェスの駒にはASCIIコードを使用しました。ボタンごとに、onclick属性を含めました。今、私はクリックされたボタンに書かれたテキスト(ASCII値)が欲しいです。それがどのように可能であるか。
onClick() メソッドでは、クリックされたビューの View 引数を受け取ります。これに対して単純に getText() を呼び出します。
public void onClick(View v) { Button myButton = (Button) v; String text = myButton.getText().toString(); }
問題のボタンへの参照が既にある場合は、それも使用できます。