我想密码保护自己的活动,我有一些问题。代码中有一些错误。编译错误:预计AnnotationName而不是
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'
}
}
}
}
}
首先,我想知道我是否正确地做了这件事。如果我不是,请指导我做正确的事。
你有什么错误?什么是写在你的Logcat? – Erol 2012-08-16 23:55:23
什么是'AvanosActivity'? – Squonk 2012-08-16 23:56:52
^我的活动名称 – 2012-08-18 15:31:29