有没有一种方法可以像在自动完成中一样在“编辑”文本的顶部显示列表?

时间:2019-03-15 13:14:30

标签: android android-layout android-fragments

希望以与AutoCompleteTextView相同的方式显示列表。下面是放在一起的代码。代码正在运行并生成windowpop,但不在Edittext之上。此外,当在列表中搜索值时,窗口正在向下移动。自从一周以来我摔断了头,然后想到可以从大家那里得到帮助。请提供帮助并告知我在哪里做错了?

View popupView = getLayoutInflater().inflate(R.layout.popup, null); 
popupWindow = new PopupWindow(popupView,ViewGroup.LayoutParams.WRAP_CONTENT, 
ViewGroup.LayoutParams.WRAP_CONTENT,false);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
popupWindow.showAsDropDown(popupView, mEditText.getScrollX(), 
mEditText.getScrollY()-50);
recyclerView = 
(RecyclerView)popupView.findViewById(R.id.popuprelativelayout);
linearLayoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(linearLayoutManager);
adapterString = new AdapterString(userpassionlist, getContext(), mEditText);
recyclerView.setAdapter(adapterString);
List<String> searchresultlist = new ArrayList<>();
for (String model : userpassionlist) {
if (model.toLowerCase().contains(separated.toLowerCase())) {
  searchresultlist.add(model);
                }
            }
adapterString.updatelist(searchresultlist);

popup.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView 
xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popuprelativelayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/appbar"
    android:layout_above="@+id/newMessage"
    android:background="@color/window_background"
    android:padding="16dp">
</android.support.v7.widget.RecyclerView>

适配器的string_row.xml

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Planet Name"
        android:id="@+id/text_id"/>
</LinearLayout>

0 个答案:

没有答案