Reputation: 1265
<android.support.v7.widget.SearchView
android:layout_width="match_parent"
android:layout_height="36dp"
android:id="@+id/search"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:background="@drawable/edit_text"
app:queryBackground="@color/white"
app:iconifiedByDefault="false"
app:showAsAction="always"
app:queryHint="Search Medicines">
</android.support.v7.widget.SearchView>
This is my xml of searchView,SetOnclicklistner is not working,when i type any character its working fine but when i click nothing happens.
setOnQueryTextListener is working, onQueryTextChange is working, setOnCloseListener is working,but SetOnclicklistner is not working.
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("my_OnSearchClick","OnSearchClick");
//not working
}
});
Upvotes: 0
Views: 1151
Reputation: 332
I got it done this way. Its working for me.
searchView.findViewById<View>(R.id.search_mag_icon).setOnClickListener {
// your code here
}
Upvotes: 0
Reputation: 1971
search.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//use this action
}
});
or
search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//use this action
search.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
Upvotes: 2