如何找到通过搜索查看或在的EditText

如何找到通过搜索查看或在的EditText

本文介绍了如何找到通过搜索查看或在的EditText android的文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的新的和我提出有一个很长的字符串,一个TextView的应用程序,我希望用户能够通过一个搜索查看或的EditText TextView的范围内寻找特定的词。我知道这是可能的,因为我看到它在某些应用中,但无法找到如何做到这一点的例子。我读了一些关于textwatcher,但不知道如何去做。我要的是按Ctrl + F工作:找到文字和应用程序选择它。
事情是这样的:

I'm new in Android and I am making an application that has a TextView with a very long string, and I want the user to be able to search for particular word within the TextView through a SearchView or EditText. I know it's possible because I saw it in some applications, but can't find any examples on how to do it. I read something about textwatcher, but not how to do it. What I want is to work as Ctrl + F: find the written word and that the app select it.Something like this:

推荐答案

那么你会clearify你怎么想搜索的文本?你只是想找到它是有或没有?而除了你想输入的的EditText每个字母来搜索?

Well will you clearify how you wanted to search the text? do you just want to find it that is there or not? and in addition do you want to search by entering each letter in the EditText?

如果你只想做两招以上是象下面这样:

if you just want to do the both above the trick is like below:

boolean hasText=false;
editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (count > 0 && (s.charAt(0) != '1')) {
               hasText=textView.getText().toString().contains(s.toString());
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

通过检查hasText真的还是假的,你不会是有或没有。

By checking the hasText true or false you will no is it there or not.

这篇关于如何找到通过搜索查看或在的EditText android的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:17