android - 当我使用 customadaptor 将单选按钮添加到列表视图时,单选按钮的布局/样式不同
问题描述
我在列表视图中使用单选按钮和复选框。当我使用自定义适配器填充列表视图时,单选按钮样式与复选框样式一起更改。当我将它添加到 XML 中没有自定义适配器的列表视图时,它的样式是默认的。附上列表视图项的 XML 布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- TextView for displaying question-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="2">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="@string/check"
android:textColor="@android:color/background_dark" />
<TextView
android:id="@+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:layout_marginLeft="20dp"
android:padding="@dimen/activity_horizontal_margin"
android:layout_gravity="center"
android:textColor="#000"
android:textSize="18sp" />
</LinearLayout>
<!-- RadioGroup for grouping of RadioButton-->
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="3">
<RadioButton
android:id="@+id/rbutt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="15"
android:textColor="#000"
android:textSize="12sp" />
<RadioButton
android:id="@+id/rbutt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="30"
android:textColor="#000"
android:textSize="12sp" />
<RadioButton
android:id="@+id/rbutt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="45"
android:textColor="#000"
android:textSize="12sp" />
</RadioGroup>
</LinearLayout>
将单选按钮添加到列表视图
//=========================================================================================================
// get the string array from string.xml file
questions = getResources().getStringArray(R.array.questions);
// get the reference of ListView and Button
simpleList = (ListView) view.findViewById(R.id.simpleListView);
submit = (Button) view.findViewById(R.id.submit);
// set the adapter to fill the data in the ListView
CustomAdapter customAdapter = new CustomAdapter(getContext().getApplicationContext(), questions);
simpleList.setAdapter(customAdapter);
//=========================================================================================================
解决方案
推荐阅读
- html - 如果单击更改按钮,为什么背景颜色没有改变?
- python - 加速 Ising-/Potts-Model Monte-Carlo 的 Python/Numpy 代码
- machine-learning - 使用 20000 个样本进行 MLPClassifier 模型精度微调
- tree - 接受二叉树并返回总和的函数
- android - app:backgroundTint 对 ViewGroup 没有影响
- php - MySQL 是否具有针对基于 URL 的攻击的内置注入攻击保护?
- zlib - zlib 在 Z_STREAM_END 之后继续膨胀
- python - 在您为应用程序应用迁移之前,项目可能无法正常工作,但迁移不起作用
- html - 溢出自动不适用于弹性容器
- ruby - 如何在Ruby中按字典顺序对数组元素进行排序