私には2つの活動があります。EnterPinとConfirmPin。配列はピンと確認ピンです。2つを比較する必要があります。ファイルを使用して配列を比較したかったのです。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"));
}
}
}
これが私が最初に配列だけでそれをやろうとしていた方法でした