【发布时间】:2018-11-04 12:50:59
【问题描述】:
我正在以编程方式添加 Spinner,使用自定义数组适配器类(扩展 ArrayAdapter)和我的 Spinner 的自定义布局(由 ImageView 和每行一个 TextView)。
一切正常,除了 Android Kit Kat:如果我点击我的 Spinner,它不会显示下拉项目,即使它包含正确的项目。我在 Android 6.x 和 7.x 上调试:它没有任何问题。 如果我使用自定义适配器和布局使用膨胀布局(在我的活动的 XML 内部),我没有任何问题,但如果我以编程方式添加我的 Spinner(使用外部 XML 布局),它就不起作用。
您知道 Android 4.4.x 中是否存在关于 Spinner/Custom Adapter 的已知兼容性问题? (如果有用我可以加代码)
编辑
我的 Activity 中的部分代码:
TableLayout container = (TableLayout)findViewById(R.id.table);
LayoutInflater inflator = this.getLayoutInflater();
//Single row I wish to add programmatically
TableLayout row = new TableLayout(getApplicationContext());
inflator.inflate(R.layout.internal_layout_to_clone, row);
container.addView(row);
//Acquire Spinner
Spinner spinner = (Spinner)row.findViewById(R.id.spinner);
//[here I use Custom Adapter to populate my Select: values are shown properly]
R.layout.internal_layout_to_clone 是一个 XML 文件,其中包含一个带有多个 TableRow(s) 的 TableLayout,其中一行包含我的 Spinner。
我不知道问题是不是我将 TableLayout 嵌套在另一个 TableLayout 中,也许这在 Android 4.4 中没有得到很好的管理
【问题讨论】:
-
你在使用谷歌的兼容支持库吗?
-
是的,我正在使用这个:com.android.support:appcompat-v7:22.2.0
-
更新appcompat库看看。可能是因为旧版本。
标签: android spinner custom-arrayadapter