我有两个活动。EnterPin 和 ConfirmPin。数组是 pin 和 confirmpin。我需要比较两者。我想用一个文件来比较数组。Enterpin 将写入文件,并且 Confirmpin 应该读取并将其数组与文件进行比较。这可能吗?我一直在做一些研究,但似乎没有什么适合我想做的事情。
public class EnterPin extends Activity {
public int[] pin = new int[4];
public Button[] buttons = new Button[10];
public int counter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enter_pin);
//getActionBar().setDisplayHomeAsUpEnabled(true);
buttons[1] = (Button)findViewById(R.id.button1);
buttons[2] = (Button)findViewById(R.id.button2);
buttons[3] = (Button)findViewById(R.id.button3);
buttons[4] = (Button)findViewById(R.id.button4);
buttons[5] = (Button)findViewById(R.id.button5);
buttons[6] = (Button)findViewById(R.id.button6);
buttons[7] = (Button)findViewById(R.id.button7);
buttons[8] = (Button)findViewById(R.id.button8);
buttons[9] = (Button)findViewById(R.id.button9);
buttons[0] = (Button)findViewById(R.id.button0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_enter_pin, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void button1(View view)
{
if(counter < 3)
{
pin[counter] = 1;
counter++;
}
else
{
PinEntered();
}
}
public void button2(View view)
{
if(counter < 3)
{
pin[counter] = 2;
counter++;
}
else
{
PinEntered();
}
}
public void button3(View view)
{
if(counter < 3)
{
pin[counter] = 3;
counter++;
}
else
{
PinEntered();
}
}
public void button4(View view)
{
if(counter < 3)
{
pin[counter] = 4;
counter++;
}
else
{
PinEntered();
}
}
public void button5(View view)
{
if(counter < 3)
{
pin[counter] = 5;
counter++;
}
else
{
PinEntered();
}
}
public void button6(View view)
{
if(counter < 3)
{
pin[counter] = 6;
counter++;
}
else
{
PinEntered();
}
}
public void button7(View view)
{
if(counter < 3)
{
pin[counter] = 7;
counter++;
}
else
{
PinEntered();
}
}
public void button8(View view)
{
if(counter < 3)
{
pin[counter] = 8;
counter++;
}
else
{
PinEntered();
}
}
public void button9(View view)
{
if(counter < 3)
{
pin[counter] = 9;
counter++;
}
else
{
PinEntered();
}
}
public void button0(View view)
{
if(counter < 3)
{
pin[counter] = 0;
counter++;
}
else
{
PinEntered();
}
}
public void PinEntered()
{
if(counter == 3)
{
TextView EnterPin = (TextView) findViewById(R.id.EnterPin);
EnterPin.setText("Pin Entered");
startActivity(new Intent("com.example.textsmslock.ConfirmPin"));
}
}
public int GetPin(int pin)
{
return pin;
}
}
.
public class ConfirmPin extends EnterPin {
public int[] pinconfirm = new int[4];
public Button[] buttons = new Button[10];
public int counter = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_confirm_pin);
//getActionBar().setDisplayHomeAsUpEnabled(true);
buttons[1] = (Button)findViewById(R.id.button1);
buttons[2] = (Button)findViewById(R.id.button2);
buttons[3] = (Button)findViewById(R.id.button3);
buttons[4] = (Button)findViewById(R.id.button4);
buttons[5] = (Button)findViewById(R.id.button5);
buttons[6] = (Button)findViewById(R.id.button6);
buttons[7] = (Button)findViewById(R.id.button7);
buttons[8] = (Button)findViewById(R.id.button8);
buttons[9] = (Button)findViewById(R.id.button9);
buttons[0] = (Button)findViewById(R.id.button0);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_confirm_pin, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void button1(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 1;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button2(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 2;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button3(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 3;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button4(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 4;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button5(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 5;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button6(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 6;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button7(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 7;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button8(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 8;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button9(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 9;
counter++;
}
else
{
ConfirmingPin();
}
}
public void button0(View view)
{
if(counter < 3)
{
pinconfirm[counter] = 9;
counter++;
}
else
{
ConfirmingPin();
}
}
public void ConfirmingPin()
{
/*for(int i = 0; i < 4; i++)
{
if(pinconfirm[i] != pin[i])
{
TextView ConfirmPin = (TextView) findViewById(R.id.ConfirmPin);
ConfirmPin.setText("Pins Do Not Match!!!!");
startActivity(new Intent("com.example.textsmslock.ConfirmPin"));
}*/
if(pinconfirm.equals((pin))) == true)
{
TextView ConfirmPin = (TextView) findViewById(R.id.ConfirmPin);
ConfirmPin.setText("Pin Confirmed");
startActivity(new Intent("com.example.textsmslock.PinComfirmation"));
}
else
{
TextView ConfirmPin = (TextView) findViewById(R.id.ConfirmPin);
ConfirmPin.setText("Pins Do Not Match!!!!");
startActivity(new Intent("com.example.textsmslock.ConfirmPin"));
}
}
}
这就是我最初尝试仅使用数组的方式