如何在Android中制作如下图所示的AutoCompleteTextView

时间:2016-05-22 07:29:00

标签: android list listview autocompletetextview

我应该如何在Android中显示建议@mention,如图片

enter image description here

1 个答案:

答案 0 :(得分:0)

使用以下代码:

<强> activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
   android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

  <AutoCompleteTextView
      android:id="@+id/autoCompleteTextView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:ems="10"
      android:layout_below="@+id/imageView"
      android:layout_alignLeft="@+id/imageView"
      android:layout_alignStart="@+id/imageView"
      android:layout_marginTop="72dp"
      android:hint="AutoComplete TextView">
      <requestFocus />
   </AutoCompleteTextView>

</RelativeLayout>

java代码:

AutoCompleteTextView text;
String[] languages={"Android ","java","IOS","SQL","JDBC","Web services"};


 @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      text=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);


      ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,languages);

      text.setAdapter(adapter);
      text.setThreshold(1);


   }

使用此代码获取输出。