【问题标题】:MultiAutoCompleteTextView list items not showing textMultiAutoCompleteTextView 列表项不显示文本
【发布时间】:2016-07-21 03:30:40
【问题描述】:

我正在开发一个 Android 应用程序,我以前从未使用过 MultiAutoCompleteTextView

在我的 layout.xml 中,我添加了:

<MultiAutoCompleteTextView
    android:id="@+id/autocomplete_subtest"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:layout_marginTop="4dp"
    android:ems="10"
    android:text="" />

在我的 DialogFragment 中:

try {
  subtestAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(R.id.autocomplete_subtest);
  ArrayAdapter<String> subtestAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_list_item_1, subtests);

  subtestAutoCompleteTextView.setAdapter(subtestAdapter);
  subtestAutoCompleteTextView.setThreshold(1);
  subtestAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
} catch (Exception e) {
  e.printStackTrace();
}

然而,这些项目以透明文本显示:

如果我单击带有空文本的列表项,它会以预期的选项完成我的 MultiAutoCompleteTextView。

知道为什么文本没有显示在项目上吗?

【问题讨论】:

    标签: android


    【解决方案1】:

    您应该更改列表项的文本颜色。可能是白色的,所以换成黑色吧。

    编辑 1

    为了解释如何解决这个问题,我点击了这个链接:How to change text color of simple list item

    基本上,使用 TextView 创建一个自定义 layout.xml 文件:

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tv"
        android:textColor="@color/font_content"
        android:padding="5sp"
        android:layout_width="fill_parent"
        android:background="@drawable/rectgrad"
        android:singleLine="true"
        android:gravity="center"
        android:layout_height="fill_parent"/>
    

    在我的代码中我改变了:

        ArrayAdapter<String> subtestAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), R.layout.my_layout_file, subtests);
    

    【讨论】:

      【解决方案2】:

      更改 ArrayAdapter,它将 100% 工作。我亲自为你测试。使用这个

      ArrayAdapter subtestAdapter = new  ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,subtests);
      

      并将对象子测试为字符串数组。像这样

      String [] subtests = {"Enamul","Ashraful", "Tonu", "Shawan","Morshed"};
      

      如果您从数据库或其他地方初始化它并像这样使用ArrayList&lt;String&gt; subtests。然后你可以将它分配给String ArrayArrayList使用这样的3行代码

      String [] subtests2 = new String[subtests.size()];
      for (int i = 0; i < subtests.size(); i++) {
          subtests2[i]=subtests.get(i).toString();
      }
      
      ArrayAdapter subtestAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,subtests2);
      

      祝你好运……

      【讨论】:

        【解决方案3】:
        <MultiAutoCompleteTextView
                    android:id="@+id/text"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:cursorVisible="true"
                    android:ellipsize="none"
                    android:ems="10"
                    android:inputType="textCapWords"
                    android:scrollHorizontally="true"
                    android:scrollbars="none"
                    android:singleLine="true"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="@color/black"
                    android:background="@null"
                     />
        

        在您的 xml 文件中尝试上面的代码。它在我的情况下工作。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-09-12
          • 1970-01-01
          • 2014-09-28
          • 1970-01-01
          • 2021-11-20
          • 1970-01-01
          相关资源
          最近更新 更多