主要布局有四个小部件 - 一个EditText和三个TextView,如下所示。
我想动态添加建议列表视图,如下所示:
怎么做?
答案 0 :(得分:3)
您可以使用AutoCompleteTextView。在http://developer.android.com/guide/topics/ui/controls/text.html中描述。
可能自定义适配器可以帮助您制作两个建议列表。看一下这个Autocompletetextview with custom adapter and filter。我想你需要在自定义适配器中创建分隔符。
如评论中所述。只需在需要显示建议时显示列表视图即可。或者粘贴在eclipse中并删除android:visibility ="去掉#34;属性,您将在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>
答案 1 :(得分:-1)
android中已经内置了一个类,可以让你思考功能。