以下のようなコードを書いてみたのですが、電卓のようなものを想定していて0~9のボタンをタップするとTextViewにそれが表示される想定です。
しかしTextViewに何も表示されずに困っています。おかしな所教えていただけるとありがたいです。
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class ActivityInput extends AppCompatActivity { Button[] buttons; String inputMoney; TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_input); textView = (TextView) findViewById(R.id.inputText); click(); } public void click() { buttons = new Button[]{findViewById(R.id.btn0), findViewById(R.id.btn1), findViewById(R.id.btn2), findViewById(R.id.btn3), findViewById(R.id.btn4), findViewById(R.id.btn5), findViewById(R.id.btn6), findViewById(R.id.btn7), findViewById(R.id.btn8), findViewById(R.id.btn9)}; for (int a = 0; a < buttons.length; a++) { buttons[a] = new Button(this); } for (int i = 0; i < buttons.length; i++) { final String s = String.valueOf(i); buttons[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputMoney = inputMoney + s; textView.setText(inputMoney); } }); } } } コード
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/21 07:25