我是android的初学者..我只擅长设计android应用程序..我不知道共享偏好..我第一次必须使用共享偏好,。所以任何人都可以在我的代码中做到这一点,以便我可以实现。以下是我的代码,请在我的代码中进行更改:告诉我如何在按钮 a 的单击上保存值,我将其临时存储在不同的变量中。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class newpage extends Activity {
String un = null;
String pass= null;
String fname= null;
String lname= null;
String age= null;
String city= null;
String coun= null;
String email= null;
String pno= null;
String repass= null;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.create_acc);
final Button b = (Button) findViewById(R.id.button3);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(newpage.this, SignIn.class);
i.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
});
final Button c = (Button) findViewById(R.id.button2);
c.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(newpage.this, CreateAcc.class);
i.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
});
final Button a = (Button) findViewById(R.id.button1);
a.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
public void onClick(View v){
EditText input1= (EditText)findViewById(R.id.fname1);
fname = input1.getEditableText().toString();
EditText input2= (EditText) findViewById(R.id.lname1);
lname = input2.getEditableText().toString();
EditText input3= (EditText) findViewById(R.id.age1);
age = input3.getEditableText().toString();
EditText input4= (EditText) findViewById(R.id.city1);
city = input4.getEditableText().toString();
EditText input5= (EditText) findViewById(R.id.country1);
coun = input5.getEditableText().toString();
EditText input6= (EditText) findViewById(R.id.email1);
email = input6.getEditableText().toString();
EditText input7= (EditText) findViewById(R.id.pno1);
pno = input7.getEditableText().toString();
EditText input8= (EditText) findViewById(R.id.uname1);
un = input8.getEditableText().toString();
EditText input9= (EditText) findViewById(R.id.passwd1);
pass = input9.getEditableText().toString();
EditText input10= (EditText) findViewById(R.id.repass1);
repass = input10.getEditableText().toString();
if((fname!=null) && (lname!=null) && (age!=null) && (city!=null) && (coun!=null) && (email!=null) && (pno!=null) && (un!=null) && (pass!=null) && (repass!=null))
{
if(pass == repass)
{
Toast.makeText(newpage.this, ".....Data Saved....." ,Toast.LENGTH_LONG).show();
Intent in = new Intent(newpage.this, SignIn.class);
in.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
}
else
{
Toast.makeText(newpage.this, ".....Password Doesn't Match....." ,Toast.LENGTH_LONG).show();
}
}
else
{
Toast.makeText(newpage.this, ".....Complete the Form Please....." ,Toast.LENGTH_LONG).show();
}
}
});
}
}