【发布时间】:2019-01-23 10:39:49
【问题描述】:
我在我的项目中使用微调器,以便用户可以从下拉列表中选择数字。我想使用微调器对话框并将其自定义为矩阵,例如 1,2,3 在一行中 4,5,6 在另一行中,但用户应该能够选择 1 或 2。这可能吗?怎么能我在布局中使用一个文本框来实现这一点。
【问题讨论】:
标签: android xml spinner android-spinner
我在我的项目中使用微调器,以便用户可以从下拉列表中选择数字。我想使用微调器对话框并将其自定义为矩阵,例如 1,2,3 在一行中 4,5,6 在另一行中,但用户应该能够选择 1 或 2。这可能吗?怎么能我在布局中使用一个文本框来实现这一点。
【问题讨论】:
标签: android xml spinner android-spinner
我认为您可以在每个布局中使用三个按钮,在每个按钮中使用 setOnClicklistener。
您的适配器中有 customView,如下所示:
private View getCustomView(int position, ViewGroup viewGroup, int type) {
View view = null;
if (type == OPEN) {
view = mLayoutInflater.inflate(R.layout.spinnerlistcurrencyopen_common, viewGroup, false);
} else if (type == CLOSE) {
view = mLayoutInflater.inflate(R.layout.spinnerlistcurrencyclose_common, viewGroup, false);
}
//find view by id your buttons here
return view;
}
你有这样的开放模式布局(R.layout.spinnerlistcurrencyopen_common):
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
>
<Button android:id="@+id/button1"
...
android:layout_weight="1"/>
<Button android:id="@+id/button2"
...
android:layout_weight="1"/>
<Button
android:id="@+id/button3"
...
android:layout_weight="1"/>
</LinearLayout>
【讨论】: