0

The main layout have four widgets- one EditText and three TextView as given below.

enter image description here

I want to add suggestion-list view dynamically as given below: enter image description here

How to do it?

Mohammed H
  • 6,880
  • 16
  • 81
  • 127
  • For solving the issue http://stackoverflow.com/questions/22962064/customized-autosuggestion-view-in-android – Mohammed H Apr 10 '14 at 10:44

2 Answers2

3

You can use AutoCompleteTextView. Described in http://developer.android.com/guide/topics/ui/controls/text.html.

Probably Custom adapter will help you to make two suggestions lists. Take a look at this Autocompletetextview with custom adapter and filter. I guess you need to create divider in custom adapter.

As described in comments. Just Make listview visible when you need to show suggestions. Or paste in eclipse and remove android:visibility="gone" attribute and you will see gray listview over textviews.

<?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"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/search"
        android:text="text1" />

    <TextView
        android:id="@+id/tv_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_1"
        android:text="text2" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_below="@id/search"
        android:background="@android:color/darker_gray"
        android:visibility="gone" />

</RelativeLayout>
Community
  • 1
  • 1
Andrew F
  • 1,712
  • 2
  • 15
  • 24
-1

There is a class already built into android which gives you think functionality.

It's called AutoCompleteTextView

jiduvah
  • 5,108
  • 6
  • 39
  • 55