Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 停止活动(未完成)_Android_For Loop - Fatal编程技术网

Android 停止活动(未完成)

Android 停止活动(未完成),android,for-loop,Android,For Loop,我有下面的代码,简单地说,当点击按钮时,一个新的活动被打开。我需要做两次检查: 1-如果编辑文本为空,只需显示警报,不打开活动(对我来说非常有效) 2-如果编辑文本不是空的,只显示警报,不打开活动(对我不起作用)+for循环使警报显示3次(字符数) 我尝试使用finish(),但没有帮助。 与我在Java中使用的(e.consume)相同的代码,可以完美地工作 这是我的密码: import android.content.Context; import android.content.Inten

我有下面的代码,简单地说,当点击按钮时,一个新的活动被打开。我需要做两次检查:

1-如果编辑文本为空,只需显示警报,不打开活动(对我来说非常有效)

2-如果编辑文本不是空的,只显示警报,不打开活动(对我不起作用)+for循环使警报显示3次(字符数)

我尝试使用finish(),但没有帮助。 与我在Java中使用的(e.consume)相同的代码,可以完美地工作

这是我的密码:

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.view.ActionMode;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import static android.provider.AlarmClock.EXTRA_MESSAGE;

public class Paal extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_paal);
}

// Action the button PAST will do
// Show the result of paal in the past
public void openPaalPast(View paalThePast) {
    // Shows the past conjungtion
    Intent paalPastView;
    paalPastView = new Intent(this, PastOfPaal.class);
    EditText getTheVerb = (findViewById(R.id.editText1));
    String theVerb = getTheVerb.getText().toString();
    // If the text is empty
    if (theVerb.isEmpty()) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setMessage("alert");
        alert.setTitle("No");
        alert.setPositiveButton("OK", null);
        alert.setCancelable(true);
        alert.create().show();
    }
    // If the text is not empty
    if (!theVerb.isEmpty()) {
        startActivity(paalPastView);
        char[] charArray = theVerb.toCharArray();
        for (char c : charArray) {
            if (!(c <= 0x05ea && c >= 0x05d0)) {
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.setMessage("alert");
                alert.setTitle("Noo");
                alert.setPositiveButton("OK", null);
                alert.setCancelable(true);
                alert.create().show();
                break; // to stop the for loop (so that the alert will be shown only once.
                // finish(); //doesn't help much, it only kill the whole activity
            }
        }
    }
  }
}
导入android.content.Context;
导入android.content.Intent;
导入android.support.v7.app.AlertDialog;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.support.v7.view.ActionMode;
导入android.view.view;
导入android.widget.EditText;
导入android.widget.TextView;
导入静态android.provider.AlarmClock.EXTRA_消息;
公共类Paal扩展应用程序活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paal);
}
//按一下按钮就可以了
//显示过去paal的结果
公共空间openPaalPast(查看paalThePast){
//显示过去的联想
意图帕马斯特视图;
paalPastView=新意图(这是PastOfPaal.class);
EditText getTheVerb=(findViewById(R.id.editText1));
String theVerb=getTheVerb.getText().toString();
//如果文本为空
if(动词.isEmpty()){
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
警报。设置消息(“警报”);
警报。设置标题(“否”);
alert.setPositiveButton(“确定”,空);
alert.setCancelable(真);
alert.create().show();
}
//如果文本不是空的
如果(!theVerb.isEmpty()){
星触觉(paalPastView);
char[]charArray=动词.toCharArray();
用于(字符c:charArray){
如果(!(c=0x05d0)){
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
警报。设置消息(“警报”);
警报。设置标题(“Noo”);
alert.setPositiveButton(“确定”,空);
alert.setCancelable(真);
alert.create().show();
break;//停止for循环(以便警报只显示一次)。
//finish();//没有多大帮助,它只会扼杀整个活动
}
}
}
}
}
2-如果编辑文本不是空的,只显示警报,不打开活动(对我不起作用)+for循环使警报显示3次(字符数)

如果您不想打开活动并仅运行一次警报,则从循环中取出警报并移除startActivity

public void openPaalPast(View paalThePast) {
    // Shows the past conjungtion
    Intent paalPastView;
    paalPastView = new Intent(this, PastOfPaal.class);
    EditText getTheVerb = (findViewById(R.id.editText1));
    String theVerb = getTheVerb.getText().toString();
    // If the text is empty
    if (theVerb.isEmpty()) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setMessage("alert");
        alert.setTitle("No verb entered");
        alert.setPositiveButton("OK", null);
        alert.setCancelable(true);
        alert.create().show();
    } else {
    // If the text is not empty
        char[] charArray = theVerb.toCharArray();
        for (char c : charArray) {
            if (!c <= 0x05ea && c >= 0x05d0) {
                 startActivity(paalPastView);  // Here I want the activity not to start, so Is there a way to do so?
            }
        }

    }
  }
}
public void openpalpast(查看paaltheast){
//显示过去的联想
意图帕马斯特视图;
paalPastView=新意图(这是PastOfPaal.class);
EditText getTheVerb=(findViewById(R.id.editText1));
String theVerb=getTheVerb.getText().toString();
//如果文本为空
if(动词.isEmpty()){
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
警报。设置消息(“警报”);
alert.setTitle(“未输入动词”);
alert.setPositiveButton(“确定”,空);
alert.setCancelable(真);
alert.create().show();
}否则{
//如果文本不是空的
char[]charArray=动词.toCharArray();
用于(字符c:charArray){
如果(!c=0x05d0){
startActivity(paalPastView);//这里我不想让活动开始,那么有什么方法可以这样做吗?
}
}
}
}
}
2-如果编辑文本不是空的,只显示警报,不打开活动(对我不起作用)+for循环使警报显示3次(字符数)

如果您不想打开活动并仅运行一次警报,则从循环中取出警报并移除startActivity

public void openPaalPast(View paalThePast) {
    // Shows the past conjungtion
    Intent paalPastView;
    paalPastView = new Intent(this, PastOfPaal.class);
    EditText getTheVerb = (findViewById(R.id.editText1));
    String theVerb = getTheVerb.getText().toString();
    // If the text is empty
    if (theVerb.isEmpty()) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setMessage("alert");
        alert.setTitle("No verb entered");
        alert.setPositiveButton("OK", null);
        alert.setCancelable(true);
        alert.create().show();
    } else {
    // If the text is not empty
        char[] charArray = theVerb.toCharArray();
        for (char c : charArray) {
            if (!c <= 0x05ea && c >= 0x05d0) {
                 startActivity(paalPastView);  // Here I want the activity not to start, so Is there a way to do so?
            }
        }

    }
  }
}
public void openpalpast(查看paaltheast){
//显示过去的联想
意图帕马斯特视图;
paalPastView=新意图(这是PastOfPaal.class);
EditText getTheVerb=(findViewById(R.id.editText1));
String theVerb=getTheVerb.getText().toString();
//如果文本为空
if(动词.isEmpty()){
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
警报。设置消息(“警报”);
alert.setTitle(“未输入动词”);
alert.setPositiveButton(“确定”,空);
alert.setCancelable(真);
alert.create().show();
}否则{
//如果文本不是空的
char[]charArray=动词.toCharArray();
用于(字符c:charArray){
如果(!c=0x05d0){
startActivity(paalPastView);//这里我不想让活动开始,那么有什么方法可以这样做吗?
}
}
}
}
}
这解决了我的问题

        // If the text is not empty
        char[] charArray = theVerb.toCharArray();
        for (char c : charArray) {
            if ((!theVerb.isEmpty()) && (c <= 0x05ea && c >= 0x05d0)) {
                startActivity(paalPastView);
                break;
            } else if (!(c <= 0x05ea && c >= 0x05d0)){
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.setMessage("alert");
                alert.setTitle("No");
                alert.setPositiveButton("OK", null);
                alert.setCancelable(true);
                alert.create().show();
                break;
            }
        }
//如果文本不是空的
char[]charArray=动词.toCharArray();
用于(字符c:charArray){
如果((!theVerb.isEmpty())&&(c=0x05d0)){
星触觉(paalPastView);
打破
}否则如果(!(c=0x05d0)){
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
警报。设置消息(“警报”);
警报。设置标题(“否”);
alert.setPositiveButton(“确定”,空);
alert.setCancelable(真);
alert.create().show();
打破
}
}
这解决了我的问题

        // If the text is not empty
        char[] charArray = theVerb.toCharArray();
        for (char c : charArray) {
            if ((!theVerb.isEmpty()) && (c <= 0x05ea && c >= 0x05d0)) {
                startActivity(paalPastView);
                break;
            } else if (!(c <= 0x05ea && c >= 0x05d0)){
                AlertDialog.Builder alert = new AlertDialog.Builder(this);
                alert.setMessage("alert");
                alert.setTitle("No");
                alert.setPositiveButton("OK", null);
                alert.setCancelable(true);
                alert.create().show();
                break;
            }
        }
//如果文本不是空的
char[]charArray=动词.toCharArray();
用于(字符c:charArray){
如果((!theVerb.isEmpty())&&(c=0x05d0)){
星触觉(paalPastView);
打破
}