Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.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
Java 逐字获取编辑文本值_Java_Socrata - Fatal编程技术网

Java 逐字获取编辑文本值

Java 逐字获取编辑文本值,java,socrata,Java,Socrata,请有人帮我解决这个问题。我是一名新手程序员,我正在尝试构建一个示例android项目,从文本字段中的文本中提取电子邮件。.xml文件已就位,但主要活动是问题所在 请务必查看下面的代码并查看问题所在。 import android.app.*; import android.os.*; import android.view.*; import android.content.*; import android.widget.*; import java.util.*; public class

请有人帮我解决这个问题。我是一名新手程序员,我正在尝试构建一个示例android项目,从文本字段中的文本中提取电子邮件。.xml文件已就位,但主要活动是问题所在

请务必查看下面的代码并查看问题所在。

import android.app.*;
import android.os.*;
import android.view.*;
import android.content.*;
import android.widget.*;
import java.util.*;

public class MainActivity extends Activity 
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }

    public void OnExtractButtonClick(View view)
    {
        EditText mainEditText1=(EditText)findViewById(R.id.mainEditText1);
        String txt = mainEditText1.getText().toString();     //Here, this code reads the
                                                                                               //whole input in the text 
                                                                                               //field (mainEditText1)...
     /* ..and that is my problem is at this point. How do i get to read the contents of 
       the text field(mainEditText1) word after word, (like .next() method does, as it 
       can only read input in the string till the next space and not all the input in
       the string.)
     */

       if  (txt.contains("@"))
       {
            Toast.makeText(MainActivity.this,"Let's see:  " +txt,
            Toast.LENGTH_LONG).show();
        }
    }
}
感谢大家使用以下方法将文本拆分为文字:

String[] words = s.split("\\s+");
for(String word : words) {
    // Do what you want with your single word here
}
注意:

表达式
\\s+
是一个将用空格字符分割字符串的表达式。

谢谢JDC,这很好。我能把它做好。再次感谢