我有一个userActivity java类,其中用户键在其用户名中,然后页面将在单击提交按钮后指向主菜单活动页面。但是当我点击按钮时,它不起作用。有谁知道为什么?以下是我的代码。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user);
Button submitBtn = (Button)findViewById(R.id.btn_submit);
nameEdit=(EditText)findViewById(R.id.edit_name);
submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getBaseContext(), SavingsGuiderMenuActivity.class);
Bundle extras = new Bundle();
extras.putString("name",nameEdit.getText().toString());
intent.putExtras(extras);
startActivity(intent);
}
});
}
答案 0 :(得分:1)
确保Manifest.xml中有另一个Activity!
答案 1 :(得分:0)
替换
Intent intent = new Intent(getBaseContext(), SavingsGuiderMenuActivity.class);
带
Intent intent = new Intent(UserActivity.this, SavingsGuiderMenuActivity.class);
如果您的活动名称为UserActivity
答案 2 :(得分:0)
Just Confirm Click的ID为:
@Override
public void onClick(View v) {
if(v.getId() == R.id.btn_submit) // Confirms Your Submit Button click
{
Toast.makeText(UserActivity.this, "Submit Button Clicked.", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(UserActivity.this, SavingsGuiderMenuActivity.class);
Bundle extras = new Bundle();
extras.putString("name",nameEdit.getText().toString());
intent.putExtras(extras);
startActivity(intent);
}
}
});
并查看Toast Message。
答案 3 :(得分:0)
@Override
public void onClick(View v) {
String txt = nameEdit.getText().toString();
Intent intent = new Intent(UserActivity.this, SavingsGuiderMenuActivity.class);
Bundle extras = new Bundle();
extras.putString("name", txt);
intent.putExtras(extras);
startActivity(intent);
}
看看这是否有效?