1

I am setting up an app that lets users click on a school and get sat scores from that school. I am getting all the data from Jsons. I want the user to click on the school, and pass the "dbn" text to the next activity and put that "dbn" text into the searchview.

In my 2nd Activity where my searchview is, the data is put into the SearchView but the list is not updated until I click back two times to get out of the SearchView. I just want the SearchView to enter the text and search without the user having to touch anything.

MyViewHolderActivity

 @NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int 
 i) {

    View view ;
    LayoutInflater inflater = LayoutInflater.from(mContext);
    view = inflater.inflate(R.layout.school_row_item, viewGroup, false);
    final MyViewHolder viewHolder = new MyViewHolder(view);

    viewHolder.layout_school.setOnClickListener(new View.OnClickListener() 
 {
        @Override
        public void onClick(View view) {

            Intent i = new Intent(mContext, SATActivity.class);
            i.putExtra("dbn", 
 mDataSchool.get(viewHolder.getAdapterPosition()).getDbn());

            mContext.startActivity(i);

        }
    });

    return viewHolder;

2nd Activity

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {

    String dbn = getIntent().getExtras().getString("dbn");

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);

    MenuItem searchItem = menu.findItem(R.id.search);
    searchItem.expandActionView();

    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQuery(dbn, true);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            s = getIntent().getExtras().getString("dbn");
            myadapter.getFilter().filter(s);
            return true;
        }
    });

    return true;
}

I expect the user to click on the RecyclerView item from the 1st activity and send the "dbn" info to the 2nd Activity searchview and have it search and update the list without the user touching anything.

update updated code after following the suggested link. data is sent to searchview but it doesn't search and update the list unless I press back twice.

Treewallie
  • 346
  • 2
  • 13

0 Answers0