我正在以编程方式添加一个Spinner,使用自定义数组适配器类(扩展ArrayAdapter)和我的 Spinner 的自定义布局(每行包含一个 ImageView 和一个 TextView)。
一切正常,除了Android Kit Kat:如果我点击我的 Spinner,它不会显示下拉项目,即使它包含正确的项目。我在 Android 6.x 和 7.x 上调试:它没有任何问题。如果我使用扩展布局(在我的活动的 XML 内部)使用自定义适配器和布局,我没有任何问题,但如果我以编程方式添加我的 Spinner(使用外部 XML 布局),它就不起作用。
您知道Android 4.4.x 中是否存在关于 Spinner/Custom Adapter的已知兼容性问题?(如果有用,我可以添加代码)
编辑
我的活动中的部分代码:
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 中没有得到很好的管理