Reputation: 123
how to passing data to searchview? I was passing data but I don'n know how to get the value in my searchview, please help me
public static final String EXTRA_ID = "Id";
@BindView(R.id.svDetail)
android.support.v7.widget.SearchView svDetail;
@BindView(R.id.rvDetail)
RecyclerView rvDetail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_member);
ButterKnife.bind(this);
String id = getIntent().getStringExtra(EXTRA_ID);
svDetail.setQuery(id,false);
and when I use TextView like // tvdetail.setText(id); it's working, why is not working for SearchView? Help please
Upvotes: 4
Views: 2187
Reputation: 8042
Firstly you need to check that you are getting the data in your Intent
, like below:-
/// GETTING INTENT DATA
Intent intent = getIntent();
if (intent.hasExtra("EXTRA_ID")) {
String id = getIntent().getStringExtra("EXTRA_ID");
YOUR_SEARCHVIEW.setActivated(true);
YOUR_SEARCHVIEW.onActionViewExpanded();
YOUR_SEARCHVIEW.setIconified(false);
YOUR_SEARCHVIEW.clearFocus();
///AT THE END YOU NEED TO SET THE TEXT
YOUR_SEARCHVIEW.setQuery(id,false);
}
else {
Log.e("NO DATA","NO DATA FOUND");
}
One more issue it can be that You are passing data Integer
value and getting String
and it can be vice-vera
Upvotes: 3
Reputation: 182
i don't know how to passing data to searchview
but just as a suggest : you can use a editText and just put a search icon to side it
whit editText you can use this code :
EditText searchBar = findViewById(R.id.searchBar);
searchBar.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Toast.makeText(MainActivity.this, "editText content changed", Toast.LENGTH_SHORT).show();
}
});
and for passing value just write searchBar.setText(id);
; this line runs the TextChangedListener and now you have a text change listener for your search bar too
Upvotes: 0