B
B
bychok3002016-12-18 14:19:11
Java
bychok300, 2016-12-18 14:19:11

SearchView to search inside a TextView, how to do?

There is an activity to which the text is transferred

public class Parsed extends Activity {

    //объявляем текствью в который будем класть наш спаршеный текст
    private TextView textView;

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

        //находим нашу текствью на активити
        textView = (TextView)findViewById(R.id.textView);
        MyTask mt = new MyTask();
        mt.execute();

    }
    class MyTask extends AsyncTask<Void, Void, Void> {

        String html;//Тут храним значение заголовка сайта
        String url = getIntent().getExtras().getString("url");//тут принимаем наш урл введенный на мэйн активити
        @Override
        protected Void doInBackground(Void... params) {

            Document doc = null;//Здесь хранится будет разобранный html документ
            try {
                //Считываем url
                doc = Jsoup.connect("http://" + url).get();
            } catch (IOException e) {
                //Если не получилось считать
                e.printStackTrace();
            }

            //Если всё считалось, то вытаскиваем из считанного html документа всё
            if (doc!=null)
                html = doc.html();
            else
                html = "Шото пошло не так, я хз че там за хня. Мож с урлом что, а мож и с самим хтмл";

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            //добавляем в текствью наш хтмл
            textView.setText(html);
        }
    }
}

I want to do a textview search using the search view, on the Internet everything is about searching in a view sheet, and I want to view the text, I found a bunch of code examples on how to do this, for example:
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_toolbar, menu);

        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) searchItem.getActionView();

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        if(null!=searchManager ) {
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        }
        searchView.setIconifiedByDefault(false);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
        return true;
    }

the question is that I don’t understand how to attach it to the text view, how to make it so that the match in the request matches the piece of text and this match is shown?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
z0rgoyok, 2016-12-18
@z0rgoyok

Look here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question