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 的东西,但它仍然让我感到困惑。谁能告诉我如何实现这一目标?
编辑:非常感谢大家。我做了一些别的事情。开关盒不起作用,所以我将 one.setOnClickListener(){.....} 之类的代码添加到每个按钮。它现在正在工作。非常感谢你们所有人。如果我不在这里发帖,就永远不会有想法。