Java 如何使用Android Studio实现自动建议UI?

Java 如何使用Android Studio实现自动建议UI?,java,android,autocompletetextview,tagging,Java,Android,Autocompletetextview,Tagging,我正在写照片应用程序。用户可以点击一个人的照片并标记它。我希望实现以下标记: 1) 用户看着照片,认出了约翰·史密斯 2) 用户单击文本输入字段 3) 用户开始键入“Jo…” 4) 会出现一个建议的gmail帐户列表,供用户选择(例如:。johny123@gmail.com, johnsmith@gmail.com, joanna@gmail.com) 5) 用户单击正确的帐户(johnsmith@gmail.com)在名单上 6) 该照片带有用户选择的帐户标记 除了第四部分,我已经实现了很

我正在写照片应用程序。用户可以点击一个人的照片并标记它。我希望实现以下标记:

  • 1) 用户看着照片,认出了约翰·史密斯
  • 2) 用户单击文本输入字段
  • 3) 用户开始键入“Jo…”
  • 4) 会出现一个建议的gmail帐户列表,供用户选择(例如:。johny123@gmail.com, johnsmith@gmail.com, joanna@gmail.com)
  • 5) 用户单击正确的帐户(johnsmith@gmail.com)在名单上
  • 6) 该照片带有用户选择的帐户标记
除了第四部分,我已经实现了很多部分。下面我展示了当前UI的代码:

// This method is invoked after the user finishes typing and clicks enter.
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
    // other code
    ...

    String usersEntry = textView.getText().toString();
    tagPhotoWith(usersLabel);
    return true;
}

当前,用户单击enter后,用户键入的任何文本都将成为照片标记。相反,我希望应用程序显示建议的gmail.com帐户列表,以便用户可以选择适当的帐户进行标记如何做到这一点?

您必须使用AutoCompleteTextView来获取保存字符串的建议(在您的情况下,它们是电子邮件ID,无论是从数据库获取还是在某个时间在程序中预定义的)

这里,在AutoCompleteTextView上设置一个适配器,以便在用户键入字符串的2或3个字符时立即为输入框获取字符串数组/Arraylist集

AutoCompleteTextView textProductView;
textProductView = (AutoCompleteTextView) findViewById(R.id.txtItem);

ArrayAdapter<String> etAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, ITEMS);
textProductView.setAdapter(etAdapter);
AutoCompleteTextView textProductView;
textProductView=(AutoCompleteTextView)findViewById(R.id.txtItem);
ArrayAdapter eAdapter=新的ArrayAdapter(这个,android.R.layout.simple\u下拉列表\u item\u 1line,ITEMS);
textProductView.setAdapter(etAdapter);

这里,ITEMS是一个字符串数组,根据从用户/数据库获取的数据或在活动中预定义的数据定义。

您必须使用AutoCompleteTextView来获取保存字符串的建议(在您的情况下,它们是电子邮件ID,无论是从数据库获取的还是在某个时间在程序中预定义的)

这里,在AutoCompleteTextView上设置一个适配器,以便在用户键入字符串的2或3个字符时立即为输入框获取字符串数组/Arraylist集

AutoCompleteTextView textProductView;
textProductView = (AutoCompleteTextView) findViewById(R.id.txtItem);

ArrayAdapter<String> etAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, ITEMS);
textProductView.setAdapter(etAdapter);
AutoCompleteTextView textProductView;
textProductView=(AutoCompleteTextView)findViewById(R.id.txtItem);
ArrayAdapter eAdapter=新的ArrayAdapter(这个,android.R.layout.simple\u下拉列表\u item\u 1line,ITEMS);
textProductView.setAdapter(etAdapter);

这里,ITEMS是一个字符串数组,根据从用户/数据库获取的数据或在“活动”中预定义的数据进行定义。

如果要显示具有良好GUI的自动完成,可以选择popupwindow,也可以使用customize listview或recyclerview,并在activty和xml中使用setvisibility Gone/Visible

我已经为我的应用程序准备了使用Listview视图的自定义自动搜索,如下所示

//activity_main.xml
<LinearLayout 
 //  parent layout
     android:orientation="vertical"
>
     < ....      /* your code for toolbar */          ..../>
     <Edittext 
       android:id="@+id/edittext"
       /*  your customization*/
      />
      <Relativelayou
      android:height="match_parent"
      android:width=""match_parent"
      >
          <LinearLayout > /*your main xml code*/ </LinearLayout>
          <ListView
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:id="@+id/lstvw"
           android:dividerHeight="0dp"
           android:visibility="gone">

         </ListView>

      </RelativeLayout>
//activity\u main.xml
< ....      /* 工具栏的代码*/../../>

如果您想使用良好的GUI显示自动完成,可以选择popupwindow,也可以使用CustomizeListView或recyclerview,并在activty和xml中使用setvisibility Gone/Visible

我已经为我的应用程序准备了使用Listview视图的自定义自动搜索,如下所示

//activity_main.xml
<LinearLayout 
 //  parent layout
     android:orientation="vertical"
>
     < ....      /* your code for toolbar */          ..../>
     <Edittext 
       android:id="@+id/edittext"
       /*  your customization*/
      />
      <Relativelayou
      android:height="match_parent"
      android:width=""match_parent"
      >
          <LinearLayout > /*your main xml code*/ </LinearLayout>
          <ListView
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:id="@+id/lstvw"
           android:dividerHeight="0dp"
           android:visibility="gone">

         </ListView>

      </RelativeLayout>
//activity\u main.xml
< ....      /* 工具栏的代码*/../../>