I’m writing a dictionary app. My search screen is very simple: centered in the Activity is the app’s logo, and aligned to the bottom of the screen is the search box. When the search box receives focus, the soft keyboard pops up and the search box moves right on top of it.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView android:id="@+id/search_logo"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:src="@drawable/logo_transparent"
android:layout_centerInParent="true"
android:contentDescription="@string/desc_logo"
/>
<EditText android:id="@+id/search_fld"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/textbox"
android:inputType="text"
android:hint="@string/search_hint"
android:padding="10dp"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
As soon as the user types even a single letter, I will make a query in Lucene for matching entries. I want the view on top of the search box to be a dynamically updating ListView for every letter that is typed (or deleted), but how can I do that from this XML layout? What is the right approach to this kind of design?
The solution seems to be more straightforward. First, create a
TextWatcherfor theEditText. Then, insideonTextChanged(), this is what you do:clear()in the adapter.notifyDataSetChanged()on the adapter.