public class Password extends Activity{
Button one, two, three, four, five, six, seven, eight, nine, zero, exit, okay;
EditText text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pass);
one = (Button) findViewById(R.id.button);
two = (Button) findViewById(R.id.button2);
three = (Button) findViewById(R.id.button3);
four = (Button) findViewById(R.id.button4);
five = (Button) findViewById(R.id.button5);
six = (Button) findViewById(R.id.button6);
seven = (Button) findViewById(R.id.button7);
eight = (Button) findViewById(R.id.button8);
nine = (Button) findViewById(R.id.button9);
exit = (Button) findViewById(R.id.button10);
zero = (Button) findViewById(R.id.button11);
okay = (Button) findViewById(R.id.button12);
}
public void onClick(View v){
switch (v.getId()){
case R.id.button:text.setText("1");
break;
case R.id.button2:text.setText("1");
break;
case R.id.button3:text.setText("1");
break;
case R.id.button4:text.setText("1");
break;
case R.id.button5:text.setText("1");
break;
case R.id.button6:text.setText("1");
break;
case R.id.button7:text.setText("1");
break;
case R.id.button8:text.setText("1");
break;
case R.id.button9:text.setText("1");
break;
case R.id.button10:text.setText("1");
break;
case R.id.button11:text.setText("1");
break;
case R.id.button12:text.setText("1");
break;
}
}
}
下に添付の写真を作りました。この活動を作りたい。sharedPreferences について何か読みましたが、まだ混乱しています。誰かがこれを達成する方法を教えてもらえますか?
編集:どうもありがとう。私は別のことをしました。switch ケースが機能しなかったので、各ボタンに one.setOnClickListener(){.....} のようなコードを追加しました。それは今働いています。皆様、本当にありがとうございました。私がここに投稿しなかったら、決してアイデアを得ることができなかったでしょう。