Android 实现带有微调器和复选框的自定义ListView

Android 实现带有微调器和复选框的自定义ListView,android,listview,checkbox,spinner,Android,Listview,Checkbox,Spinner,我所要做的就是拥有一个带有文本视图的列表视图,或者在右侧有一个微调器,或者有一个复选框。 我在这件事上遇到了太多的困难,太可笑了。谁能帮帮我吗( 到目前为止,我已经实现了一个微调器(我为行星创建了R.array,所以它确实有效) 以下是XML文件main2.XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/andro

我所要做的就是拥有一个带有文本视图的列表视图,或者在右侧有一个微调器,或者有一个复选框。 我在这件事上遇到了太多的困难,太可笑了。谁能帮帮我吗(

到目前为止,我已经实现了一个微调器(我为行星创建了R.array,所以它确实有效)

以下是XML文件main2.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="Please select a planet:"
/>

<Spinner 
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/planet_prompt"
/>
<Spinner 
android:id="@+id/spinner1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/planet_prompt1"
/>

</LinearLayout>


请帮助:“(

您可以做的是:创建一个类似于普通的列表视图。然后创建一个单独的xml文件,其中包含您希望列表视图中每个项目的布局。这将适用于微调器和复选框,并且简单易创建

请考虑:

<...xml header stuff .../>

<LinearLayout android:id="@+id/ll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Spinner (or Checkbox) android:id="@+id/spinny"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <TextView android:id="@+is/texty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>


然后,对于您的活动,您将像平常一样创建一个ListView。在ListView适配器的
getView(…args…
方法中为每个ListView项扩展此布局。

此搜索应该对您有所帮助,这个问题已经回答了几次:-)我曾想过要这么做,但我现在很难将我的大脑集中在它周围……最终我想复制android为每个android手机上的标准通用报警应用程序所做的。它在列表视图中有一组选项,其中一些选项带有复选框和微调器。我是否必须从中为每个行视图创建xml抓取并设置微调器和复选框的onClickListeners??我真的很感谢您的帮助,顺便说一句。好的,它开始变得更有意义了。让我试试,我会让您知道它是如何运行的:DHey伙计,这里还是新的。有什么方法我可以PM您吗?目前我正在尝试,它只是用文本视图填充listView,而不是微调器就像我想要的那样。我是不是弄错了?不能在这个小回复框中显示我的代码。@cj1098-抱歉,我现在不能花那么多时间。在工作和其他方面。你需要在
getView()中向微调器添加数据
方法,您需要对每个微调器执行此操作。我建议使用此复选框。它将更简单,所需内容更少。@AedonEtLIRA让我们
<...xml header stuff .../>

<LinearLayout android:id="@+id/ll"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Spinner (or Checkbox) android:id="@+id/spinny"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <TextView android:id="@+is/texty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>