1

Summary I am sending text from one activity and putting that text in a SearchView in another activity. How can I make the SeachView auto submit the text without opening up the keyboard?

What I have Tried:

1) searchView.performClick(); doesn't do anything in my @Override protected void onCreate(Bundle savedInstanceState)

2) and also I have searchView.setQuery(dbn, true); which sets the submit to true but it doesn't do anything either. I also have read this post but it doesn't help my problem (Is it possible to pass search context data using the Search Widget (SearchView) only?)

3) and also (https://www.zidsworld.com/android-development/set-text-in-searchview-programmatically-in-java-android/).

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


    // Gets text from first activity
    String dbn = getIntent().getExtras().getString("dbn");

    SearchView searchView = findViewById(R.id.searchID);

    // sets text from first activity
    searchView.setQuery(dbn, true);

    // try to submit the text
    searchView.performClick();

    // clears the focus to prevent the keyboard from popping up
    searchView.clearFocus();

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() 
  {
        @Override
        public boolean onQueryTextSubmit(String s) {
            myadapter.getFilter().filter(s);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            myadapter.getFilter().filter(s);
            return true;
        }
    });

      // json code ect...

   }

Expected and actual results: I expect the text from activity one to auto submit in the SearchView in the 2nd activity while hiding the keyboard. What actually happens is the text is sent from activity one to the SearchView in activity 2, except it doesn't auto submit the text.

I appreciate the time to read this, and I thank you for any help. Thank you!

Treewallie
  • 346
  • 2
  • 13

0 Answers0