我正在尝试自己对活动进行密码保护,但遇到了一些问题。代码中有一些错误。
import com.foo.avanos.AvanosActivity;
import com.foo.avanos.R;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.content.Intent;;
public class ChangePassword extends AvanosActivity{
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.settings);
Button submitButton = (Button) findViewById(R.id.button2);
submitButton.setOnClickListener(this);
Button ChangePasswordButton = (Button) findViewById(R.id.button2);
ChangePasswordButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
Button EnterButton2 = (Button) findViewById(R.id.button2);
//Below, it's telling me 'Syntax error on tokens, AnnotationName expected instead'
EnterButton2.setOnClickListener(new View.OnClickListener() {
public void onClick2(View v) {
EditText passwordEditText = (EditText) findViewById(R.layout.password);
SharedPreferences prefs = this.getApplicationContext().getSharedPreferences("prefs_file",MODE_PRIVATE);
String NewPassword = prefs.getString("password","");
String CurrentPassword = prefs.getString("password","NewPassword");
if(NewPassword.equals(CurrentPassword)){
Editor edit = prefs.edit();
edit.putString("password",passwordEditText.getText().toString());
edit.commit();
}
else {
Toast.makeText(getBaseContext(),"Passwords do not match",Toast.LENGTH_SHORT).show();
return;
}
//Below, it's telling me 'Syntax error, insert ";" to complete Statement'
}
}
}
}
}
首先,我想知道我这样做是否正确。如果我不是,请指导我做正确的事。