0

我正在以编程方式添加一个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 中没有得到很好的管理

4

2 回答 2

0

我相信问题出在代码的某个地方,如果您可以上传它,我会看看。顺便说一句,我一直在为微调器使用外部库,这使得微调器的使用更容易,而且看起来比普通的更好。 https://github.com/ybq/Android-SpinKit

于 2018-05-25T07:57:54.517 回答
0

我刚刚解决了我的问题。我改变了我用来膨胀我的外部布局的方式:

TableLayout table = (TableLayout)findViewById(R.id.table);
LayoutInflater inflator = this.getLayoutInflater();
TableLayout row = new TableLayout(getApplicationContext());
inflator.inflate(R.layout.internal_layout_to_clone, row);
table.addView(row);

对此:

TableLayout table = (TableLayout)findViewById(R.id.table);
TableLayout row = (TableLayout)LayoutInflater.from(this).inflate(R.layout.internal_layout_to_clone, null);
table.addView(row);

我不知道为什么,可能一些涉及的方法与旧的 Android 版本不完全兼容,但现在它在每个测试的版本上都能正常工作。

谢谢

于 2018-05-29T08:19:35.870 回答