2015-05-09 57 views
-1

我正在嘗試通過單擊進行另一項活動的登錄活動。但它給我錯誤。這裏是代碼....我正在嘗試進行登錄活動,以繼續顯示另一個顯示用戶名稱的活動。

public void onButtonClick(View v) { 
    if(v.getid() == R.id.Blogin) 
    { 
     EditText a=(EditText) findViewById(R.id.TFUserName); 
     String str= a.getText().toString(); 
     Intent i = new Intent(this, SignIn.class); 
     i.putExtra("Username",str); 
     startActivity(i); 

    } 
} 

其給我錯誤的視圖和getid ..任何人都可以幫助我解決這個錯誤?

+1

你能發佈你的錯誤日誌嗎? – Meenaxi

+0

plz發佈您的logcat ....以便我們可以識別您的問題在哪裏? –

+0

發佈您的代碼。 – dsharew

回答

0

試試這段代碼。

第一項活動: -

Intent i = new Intent(FirstScreen.this, SecondScreen.class); 
String keyIdentifer = null; 
i.putExtra("STRING_I_NEED", strName); 

次活動: -

String newString; 
if (savedInstanceState == null) { 
    Bundle extras = getIntent().getExtras(); 
    if(extras == null) { 
     newString= null; 
    } else { 
    newString= extras.getString("STRING_I_NEED"); 
    } 
} else { 
    newString= (String)savedInstanceState.getSerializable("STRING_I_NEED"); 

} 完整的代碼..

或 您可以使用共享偏好來保存用戶登錄的值。

相關問題