- Registration_Form.java
を移すませんこれは私の登録フォームであると私は私を助け、私は間違ってコーディングをやっているところを教えてくださいSharedPreferencesてからログインしてから、登録からユーザ名を移動したいです。あなたのトーストでSharedPreferences値
package com.example.android.demo;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
public class Registration_Form extends AppCompatActivity {
EditText e1, m1, p1, p2, em;
Button b1;
CheckBox ch;
RadioButton r1, r2;
RadioGroup ra;
SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration__form);
e1 = (EditText) findViewById(R.id.username);
m1 = (EditText) findViewById(R.id.phone);
p1 = (EditText) findViewById(R.id.password);
p2 = (EditText) findViewById(R.id.conpassword);
em = (EditText) findViewById(R.id.email);
b1 = (Button) findViewById(R.id.submit);
ch = (CheckBox) findViewById(R.id.checkedTextView);
r1 = (RadioButton) findViewById(R.id.male);
r2 = (RadioButton) findViewById(R.id.female);
ra = (RadioGroup) findViewById(R.id.radioGroup);
//sharedPreferences Configuration
sharedPreferences = getSharedPreferences("Demo", Context.MODE_PRIVATE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (e1.getText().toString().isEmpty() || e1.getText().toString().length() < 6) {
e1.setError("Please Enter At Least 6 Character");
} else {
if (m1.getText().toString().isEmpty() || m1.getText().toString().length() < 10) {
m1.setError("Please Enter Correct Mobile Number");
} else {
if (m1.getText().toString().startsWith("9") || m1.getText().toString().startsWith("8") || m1.getText().toString().startsWith("7")) {
} else {
Toast.makeText(getApplicationContext(), "Mobile Number Start With 9/8/7 ", Toast.LENGTH_SHORT).show();
}
if (p1.getText().toString().isEmpty() || p1.getText().toString().length() < 6 || p2.getText().toString().isEmpty() || p2.getText().toString().length() < 6) {
Toast.makeText(getApplicationContext(), "Please Enter At Lease 6 Character", Toast.LENGTH_SHORT).show();
} else {
if (!p1.getText().toString().equals(p2.getText().toString())) {
Toast.makeText(getApplicationContext(), "Password Not Matched", Toast.LENGTH_SHORT).show();
} else {
if (em.getText().toString().isEmpty()) {
em.setError("Please Enter Valid Email");
} else {
if (r1.isChecked() == true || r2.isChecked() == true) {
if (ch.isChecked() == true) {
Toast.makeText(getApplicationContext(), "Register Successfully", Toast.LENGTH_SHORT).show();
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("userName", e1.getText().toString());
editor.commit();
Intent login = new Intent(getApplicationContext(),Login.class);
startActivity(login);
finish();
} else {
Toast.makeText(getApplicationContext(), "Please Select The Check Box To Further Proceed", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(), "Please Select One Gender", Toast.LENGTH_SHORT).show();
}
}
}
}
}
}
}
});
}
}
2.Login.java
package com.example.android.demo;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Login extends AppCompatActivity {
EditText e1,e2;
Button b1;
TextView t1;
SharedPreferences loginShare;
String myLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
e1 = (EditText)findViewById(R.id.username);
e2 = (EditText)findViewById(R.id.password);
b1 = (Button) findViewById(R.id.login);
t1 = (TextView)findViewById(R.id.registrationYourSelf);
loginShare = getSharedPreferences("Demo", Context.MODE_PRIVATE);
myLogin = loginShare.getString("userName", null);
Toast.makeText(getApplicationContext(),myLogin,Toast.LENGTH_LONG);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(e1.getText().toString().equals("admin") && e2.getText().toString().equals("admin")){
Toast.makeText(getApplicationContext(), "Login Successfully", Toast.LENGTH_SHORT).show();
Intent mainpage = new Intent(getApplicationContext(),MainActivity.class);
startActivity(mainpage);
finish();
}else {
Toast.makeText(getApplicationContext(),"Credentials Not Match",Toast.LENGTH_SHORT).show();
}
}
});
t1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent registrationForm = new Intent(getApplicationContext(),Registration_Form.class);
startActivity(registrationForm);
//finish();
}
});
}
}
はトーストメッセージが表示さでしたか? – rafsanahmad007
何が問題なのか教えてください。 – nasch
あなたはあなたが資格情報admin | adminでしかログインできないことに気づきましたか?あなたのログインフォームは登録ユーザー名とパスワードを全くサポートしません – BAAAZINGA