只有當條件為真時,我才需要從一個活動轉到另一個活動 如果條件為假,我需要它保持在同一個活動中
真正的條件正在起作用,它正在將我轉移到第二個活動雖然(false)正在關閉整個程式并且不要留在活動中,我該如何防止?我的代碼如下(下面 -else- 我添加了一些方法,但它們根本不起作用):
Intent move = new Intent(this, MainActivity.class);
if(minString != null && maxString !=null) {
startActivity(move);
}
else {
// minString.setError( "fill the field!" );
//Toast.makeText(getApplicationContext(), "fill the field", Toast.LENGTH_SHORT).show();
//Intent move = new Intent(this, FirstActivity.class);
// startActivity(move);
}
uj5u.com熱心網友回復:
假設“minstring”和“maxstring”是輸入。
嘗試在按鈕中使用此代碼
EditText minstring = (EditText) findViewById(R.id.YOUR_ID);
EditText maxstring = (EditText) findViewById(R.id.YOUR_ID);
String strMinString = minstring.getText().toString();
String strMaxString = maxstring.getText().toString();
Intent move = new Intent(this, MainActivity.class);
if(TextUtils.isEmpty(strMinString) && TextUtils.isEmpty(strMaxString) ) {
minstring.setError("Your message");
maxstring.setError("Your message");
return;
}else if(minString != null && maxString !=null) {
startActivity(move);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/316380.html
上一篇:滲透測驗中的一波三折
