2016-03-30 15 views
0
public class Loginscreen extends Activity { 
private EditText phonenumber,password; 
private Button signin,joinus,supportus; 
private TextView forgot_password; 
String mobilenumber; 
String passwordtxt; 
@Override 
protected void onCreate(final Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.loginscreen); 
    phonenumber = (EditText) findViewById(R.id.edt_username); 
    password = (EditText) findViewById(R.id.edt_password); 
    signin = (Button) findViewById(R.id.bt_signin); 
    joinus = (Button) findViewById(R.id.bt_joinus); 
    supportus = (Button) findViewById(R.id.bt_supportus); 
    forgot_password = (TextView) findViewById(R.id.txt_remember_pawd); 
    final String user = phonenumber.getText().toString(); 
    final String pass = password.getText().toString(); 



    signin.setOnClickListener(
      new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        //final Intent intent; 
        SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE); 
        final String pasword = pref.getString("pwd", null); 
        final String phnenumber = pref.getString("mobilenumber", null); 
        if (pass == pasword && user == phnenumber && !pass.isEmpty()){ 
         Toast.makeText(Loginscreen.this, "correct ", Toast.LENGTH_SHORT).show(); 
               } 
              else{ 
         Toast.makeText(Loginscreen.this, "Incorrect Mobile number or password", Toast.LENGTH_SHORT).show(); 

        } 

       } 
      }); 

.... iGeçerli ekranı nasıl karşılaştırabilirim Metin alanı değerini sonraki ekranda bulunan paylaşılan tercih değeriyle düzenleyin? i şimdiki metin düzenleme değeri ile paylaşılan tercih değeri karşılaştırabilirsiniz nasıl yukarıdaki kodda

@Override 
    public void onPostExecute(String result) { 
     JSONObject jsonobject = null; 
     try { 
      jsonobject = new JSONObject(result); 
      JSONObject object = jsonobject.getJSONObject("data"); 
      String id = object.getString("_id"); 
      SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE); 
      pref.getString("key_name1",null); 
     //final String encoded = pref.getString("key_name1",null); 
     String password = getIntent().getStringExtra("_password"); 
     String mobilen = getIntent().getStringExtra("mobile"); 
     SharedPreferences.Editor editor = pref.edit(); 
     editor.putString("pwd",password); 
     editor.putString("mobilenumber",mobilen); 
     editor.putString("user_id",id); 
     editor.commit(); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

Yukarıdaki kod başka bir etkinlikle mevcuttur .. başka bir sayfaya tercihini paylaştı kullandık. .Her ikisi de eşit olan değerleri karşılaştırmak için LoginScreen'de bu paylaşılan tercih değerini kullanabilir miyim?

+0

Bundle ve putExtra'yu Niyet'e kullanabilir veya 'Static' Variable'ı kullanabilirsiniz. – Aizen

cevap

0

== yerine equals() kullanmalısınız.

if (pass == pasword && user == phnenumber && !pass.isEmpty()){ 
    Toast.makeText(Loginscreen.this, "correct ", Toast.LENGTH_SHORT).show(); 
} else{ 
    Toast.makeText(Loginscreen.this, "Incorrect Mobile number or password", Toast.LENGTH_SHORT).show(); 
} 

için: bu kod parçasını değiştirin

if (password.getText().toString().equals(password) && phonenumber.getText().toString().equals(phnenumber) && !pass.isEmpty()){ 
     Toast.makeText(Loginscreen.this, "correct ", Toast.LENGTH_SHORT).show(); 
    } else{ 
     Toast.makeText(Loginscreen.this, "Incorrect Mobile number or password", Toast.LENGTH_SHORT).show(); 
    } 
+0

Cevabınız için teşekkürler efendim –

0

Sen niyet ile yapabilirsiniz. İlk ekranınızda bulunan , bazı tuşlara aşağıdaki kodu yazınız. onCreate içinde kodunun altında ikinci ekran yazma()

String value=getIntent().getStringExtra("editTextvalue"); 

campare sizin sharedPreferences değeri ile bu değer içinde

Intent i=new Intent(FirstActivity.this,SecondActivity.class); 
i.putExtra("editTextvalue",editText.getText().toString()); 
startActivity(i); 

.

İlgili konular