我的第一个活动代码如下
public class MainActivity extends Activity {
Button mainActLoginBtn, mainActCreateBtn;
EditText mainActUserEdt, mainActPswEdt;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainActLoginBtn = (Button) findViewById(R.id.btn1);
mainActCreateBtn = (Button) findViewById(R.id.btn2);
mainActUserEdt = (EditText) findViewById(R.id.edt1);
mainActPswEdt = (EditText) findViewById(R.id.edt2);
tv = (TextView) findViewById(R.id.tview);
mainActLoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String userString = mainActUserEdt.getText().toString();
String pswString = mainActPswEdt.getText().toString();
if (userString.contentEquals("Dev")
&& pswString.contentEquals("1234")) {
tv.setText("Welcome " + userString
+ "Click Proceed to further process");
Intent successAct = new Intent("com.example.a_m_s.INTRO");
startActivityForResult(successAct, 0);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
应用程序无法成功运行第一个窗口显示,这是一个登录窗口,输入登录凭据并单击登录按钮,Android Emulator中生成错误 如果需要更多参考代码,我无法弄清楚可能出现什么问题请向我们索取。
答案 0 :(得分:0)
试试这个..
Intent successAct = new Intent(MainActivity.this,INTRO.class);
startActivity(successAct);
示例:强>
mainActLoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String userString = mainActUserEdt.getText().toString();
String pswString = mainActPswEdt.getText().toString();
if (userString.contentEquals("Dev")
&& pswString.contentEquals("1234")) {
tv.setText("Welcome " + userString
+ "Click Proceed to further process");
Intent successAct = new Intent(MainActivity.this,INTRO.class);
startActivity(successAct);
}
}
});
答案 1 :(得分:0)
除了撰写startActivityForResult(successAct, 0);
之外,您还需要撰写startActivity(successAct);
mainActLoginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String userString = mainActUserEdt.getText().toString();
String pswString = mainActPswEdt.getText().toString();
if (userString.contentEquals("Dev")
&& pswString.contentEquals("1234")) {
tv.setText("Welcome " + userString
+ "Click Proceed to further process");
Intent successAct = new Intent("com.example.a_m_s.INTRO");
startActivity(successAct);
}
}
});