[英]how to avoid a starting activity when it's called
我会尝试解释它,我有两个活动,我用按钮创建一个活动。 当按下按钮时我不希望第二个活动开始,我该怎么做? 如果你需要一些代码请告诉我!
尝试这个
if(yourtextfield1.getText().toString().length>0&&yourtextfield2.getText().toString().length>0&&yourtextfield3.getText().toString().length>0){
//start your second activity here
}else {
// give a warning to user
}
enable=false
。 有一个像这样的代码
private void validateButton()
{
if(isAllDataEntered())
((Button)findViewById(R.id.btn_submit)).setEnabled(true);
}
然后你为所有的editBoxs添加这样的东西。
editUserName.setOnEditorActionListener(this);
并实现这些方法并在onTextChanged
方法中调用它,并调用此validateButton
方法。
在isAllDataEntered
方法中,您可以检查是否输入了文本。
放一张支票就好。
EditText et1 = (EditText) findViewbyId(r.id.edittext1);
EditText et2 = (EditText) findViewbyId(r.id.edittext2);
EditText et3 = (EditText) findViewbyId(r.id.edittext3);
if(!(et1.getText().equals("") &&et2.getText().equals("") &&et3.getText().equals(""))){
StartActivity();
}
else
{
alertUser();
}
其中edittext1,edittext2,edittext3是xml中的ed editext
将menifest中活动的launchMode设置为singleTop
<activity
android:name="MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.