I have an actionBar with a searchView icon. I click on searchView icon and softInputMode keyboard appears and my ListView appears for searching. However, when you go to close searchView, the searchView closes but I can't get the ListView to also close when searchView closes.
Here's my code for ListView in activity_maps.xml
<ListView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="0dp"
/>
MapsActivity.java
ArrayAdapter<String> adapter;
@Override
public boolean onCreateOptionsMenu(final Menu menu){
final ListView lv = (ListView) findViewById(R.id.list);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.addAll(Arrays.asList(getResources().getStringArray(R.array.array_states_trial)));
adapter = new ArrayAdapter<>(MapsActivity.this, android.R.layout.simple_list_item_1, arrayList);
lv.setAdapter(adapter);
lv.setVisibility(View.INVISIBLE);
So initially when MapsActivity.java loads I don't want the ListView to show right away.
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lv.setVisibility(View.VISIBLE);
}
});
I want the listView to show when searchView is clicked open and keyboard pops up.
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
lv.setVisibility(View.INVISIBLE);
return false;
}
});
In the above code, I want the listView to close, disappear, be invisible, but it doesn't.
btw I'm referring to the "Back" button in the actionBar that comes with closing searchView.
When searchView and keyboard closes, I want the ListView to also close but for some reason the code isn't recognized and listView never closes.
How do I close ListView?