我有一个登录按钮,按下该按钮会将用户发送到另一个活动,并将在 TextView 中发布用户名。那部分工作正常。问题是当我尝试将第二个活动 TextView 中的用户名传递给第三个活动 TextView 时,它没有显示出来。android:hint 显示为文本,所以我知道 xml 很好。我已经尝试了在这个网站上可以找到的每一种“putExtra”意图。我想我只是错过了一些东西..帮助。我对 android 完全陌生,所以请嘲笑新手 :)
活动二
public class DashboardActivity extends Activity {
UserFunctions userFunctions;
Button btnLogout;
Button scanButton;
Button userinfo;
Button help;
Button receipt;
TextView showmsg;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/**
* Dashboard Screen for the application
* */
// Check login status in database
userFunctions = new UserFunctions();
if(userFunctions.isUserLoggedIn(getApplicationContext())){
setContentView(R.layout.dashboard);
scanButton = (Button) findViewById(R.id.scanButton);
btnLogout = (Button) findViewById(R.id.btnLogout);
userinfo = (Button) findViewById(R.id.userinfo);
help = (Button) findViewById(R.id.help);
receipt = (Button)findViewById(R.id.receipt);
showmsg = (TextView)findViewById(R.id.showmsg);
Intent in = getIntent();
if (in.getCharSequenceExtra("usr") != null) {
final TextView setmsg = (TextView)findViewById(R.id.showmsg);
setmsg.setText("User: "+in.getCharSequenceExtra("usr"));
}
btnLogout.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
userFunctions.logoutUser(getApplicationContext());
Intent login = new Intent(getApplicationContext(), LoginActivity.class);
login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
// Closing dashboard screen
finish();
}
});
// Link to CC
scanButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(),
MyScanActivity.class);
startActivity(i);
finish();
}
});
// Create a customer receipt
receipt.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(DashboardActivity.this, ReceiptActivity.class));
intent.putExtra("TextView",showmsg);
startActivity(intent);
finish();
}
});
// Link to User info
userinfo.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(),
UserInfoActivity.class);
startActivity(i);
finish();
}
});
// Link to Help info
help.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(),
HelpActivity.class);
startActivity(i);
finish();
}
});
}else{
// user is not logged in show login screen
Intent login = new Intent(getApplicationContext(), LoginActivity.class);
login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(login);
// Closing dashboard screen
finish();
}
}
}