Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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_Search_Textview_Highlight - Fatal编程技术网

Android 在文本视图中搜索具有长文本的单词

Android 在文本视图中搜索具有长文本的单词,android,search,textview,highlight,Android,Search,Textview,Highlight,这是我的java代码,我的文本视图中有一个大文本,我想搜索word并使其高亮显示,这样就很容易找到bt。我不想创建一个按钮。一旦我们输入编辑文本,它应该高亮显示该单词。 这是我所做的和它的工作,直到我在编辑文本中输入一些字,但我想突出显示的字请帮助我 public class sample extends AppCompatActivity implements { TextView textView; EditText editText;

这是我的java代码,我的文本视图中有一个大文本,我想搜索word并使其高亮显示,这样就很容易找到bt。我不想创建一个按钮。一旦我们输入编辑文本,它应该高亮显示该单词。 这是我所做的和它的工作,直到我在编辑文本中输入一些字,但我想突出显示的字请帮助我

 public class sample extends AppCompatActivity implements  {
        TextView textView;
       EditText editText;
     
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_2);
            Toolbar toolbar = findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
            toolbar.setTitle("sample");
    
            if (getIntent().hasExtra("a1")) {
                 Stribg data= getIntent().getStringExtra("a1");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
    
            } else if (getIntent().hasExtra("a2")) {
                String data = getIntent().getStringExtra("a2");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a3")) {
                String data = getIntent().getStringExtra("a3");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a4")) {
                String data = getIntent().getStringExtra("a4");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a5")) {
                String data = getIntent().getStringExtra("a5");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a6")) {
                String data = getIntent().getStringExtra("a6");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a7")) {
                String data = getIntent().getStringExtra("a7");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a8")) {
                String data = getIntent().getStringExtra("a8");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a9")) {
                String data = getIntent().getStringExtra("a9");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a10")) {
                String data = getIntent().getStringExtra("a10");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a11")) {
                String data = getIntent().getStringExtra("a11");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a12")) {
                String data = getIntent().getStringExtra("a12");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a13")) {
                String data = getIntent().getStringExtra("a13");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a14")) {
                String data = getIntent().getStringExtra("a14");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a15")) {
                String data = getIntent().getStringExtra("a15");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a16")) {
                String data = getIntent().getStringExtra("a16");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a17")) {
                String data = getIntent().getStringExtra("a17");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            } else if (getIntent().hasExtra("a18")) {
                String data = getIntent().getStringExtra("a18");
                TextView textView = findViewById(R.id.Text1);
                textView.setText(data);
            }

       public void onClick(View view) {
            String textToHighlight=editText.getText().toString();
            String replaceWith="<span style='background-color:yellow'>"+textToHighlight+"</span>";
            String originalText = textView.getText().toString();
            String modifiedtext= originalText.replaceAll(textToHighlight,replaceWith);
            textView.setText(Html.fromHtml(modifiedtext));
        }
    }
公共类示例扩展了AppCompatActivity实现{
文本视图文本视图;
编辑文本编辑文本;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_2);
Toolbar Toolbar=findviewbyd(R.id.Toolbar);
设置支持操作栏(工具栏);
工具栏.setTitle(“示例”);
if(getIntent().hasExtra(“a1”)){
Stribg data=getIntent().getStringExtra(“a1”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a2”)){
字符串数据=getIntent().getStringExtra(“a2”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a3”)){
字符串数据=getIntent().getStringExtra(“a3”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a4”)){
字符串数据=getIntent().getStringExtra(“a4”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a5”)){
字符串数据=getIntent().getStringExtra(“a5”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a6”)){
字符串数据=getIntent().getStringExtra(“a6”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a7”)){
字符串数据=getIntent().getStringExtra(“a7”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a8”)){
字符串数据=getIntent().getStringExtra(“a8”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a9”)){
字符串数据=getIntent().getStringExtra(“a9”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a10”)){
字符串数据=getIntent().getStringExtra(“a10”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a11”)){
字符串数据=getIntent().getStringExtra(“a11”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a12”)){
字符串数据=getIntent().getStringExtra(“a12”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a13”)){
字符串数据=getIntent().getStringExtra(“a13”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a14”)){
字符串数据=getIntent().getStringExtra(“a14”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a15”)){
字符串数据=getIntent().getStringExtra(“a15”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a16”)){
字符串数据=getIntent().getStringExtra(“a16”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a17”)){
字符串数据=getIntent().getStringExtra(“a17”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}else if(getIntent().hasExtra(“a18”)){
字符串数据=getIntent().getStringExtra(“a18”);
TextView TextView=findViewById(R.id.Text1);
textView.setText(数据);
}
公共void onClick(视图){
String textToHighlight=editText.getText().toString();
字符串替换为=”“+textToHighlight+”;
String originalText=textView.getText().toString();
字符串modifiedtext=originalText.replaceAll(textToHighlight,replaceWith);
setText(Html.fromHtml(modifiedtext));
}
}