Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从可扩展列表视图中获取所有复选框、单选按钮和评级:android_Android_Android Layout_Android Listview - Fatal编程技术网

从可扩展列表视图中获取所有复选框、单选按钮和评级:android

从可扩展列表视图中获取所有复选框、单选按钮和评级:android,android,android-layout,android-listview,Android,Android Layout,Android Listview,我有一个可扩展的列表视图,其中包含了一个简短的调查(3-4个字段供用户插入数据)每个记录,我们有。然后我们有一个按钮,他们可以点击该按钮将数据提交到我们的服务器。当他们按下按钮时,我需要它来获取调查中的所有数据并将其发送到我们的网站。我已经弄清楚了它的发送部分;我正在努力从调查中获取所有数据 我已经浏览了很多相关的帖子/谷歌搜索结果,并试图将他们的ListView解决方案应用到ExpandedListView中,但我还没能让它们中的任何一个正常工作。我花了好几个小时试图找到一些可行的解决方案,但

我有一个可扩展的列表视图,其中包含了一个简短的调查(3-4个字段供用户插入数据)每个记录,我们有。然后我们有一个按钮,他们可以点击该按钮将数据提交到我们的服务器。当他们按下按钮时,我需要它来获取调查中的所有数据并将其发送到我们的网站。我已经弄清楚了它的发送部分;我正在努力从调查中获取所有数据

我已经浏览了很多相关的帖子/谷歌搜索结果,并试图将他们的ListView解决方案应用到ExpandedListView中,但我还没能让它们中的任何一个正常工作。我花了好几个小时试图找到一些可行的解决方案,但唉,我想不出来

我想我的部分问题是我不确定儿童视图是如何在可扩展列表视图中发挥作用的。无论如何,下面是我的代码,希望比我聪明的人能帮助我解决这个问题

因此,我有我的ExpandableListView片段_survey.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    tools:context="edu.ucr.aum.fragments.SurveyFragment$PlaceholderFragment">

    <ExpandableListView
        android:id="@+id/list_view_survey_list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/rowPaddingMedium"
        android:layout_marginRight="@dimen/rowPaddingMedium"
        android:divider="@null"
        android:dividerHeight="0dp"
        android:clipToPadding="false"
        android:scrollbarStyle="outsideOverlay" />

    <TextView
        android:id="@+id/tvResponseCode"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/list_view_survey_list"
        android:text="Response Code: "/>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Submit Survey"
        android:layout_below="@+id/tvResponseCode"
        android:id="@+id/btnSubmitSurvey" />

</RelativeLayout>

您应该创建一个类似数组的数据结构来存储调查数据,我会按组和/或子位置对其进行索引,只要对数据有意义。然后,您应该为每个问题输入添加侦听器,当问题回答为“是”时,在适当的位置将答案添加到该数据结构中。然后,当您按下submit按钮时,它可以迭代该数据结构,提示未回答的问题或填写默认值,将所有内容收集在一起,然后提交


基本上,没有简单的/内置的方式来访问我能够找到的动态/可重用行的各个行。当哪一行的上下文很重要时,我发现最好的方法是拥有自己的数据结构,该结构使用组/子位置来查找正在按下的按钮,因为每一行都有一个具有相同id的按钮。我还在创建时使用setHint将组位置/索引存储在按钮中,以便在侦听器的上下文中确定位置。

我不得不通过一项可怕的黑客工作来完成这项工作,但它是有效的。我为每一行添加了一个按钮,允许用户“保存”该行。当他们保存行时,数据将保存到我的数据结构中。不幸的是,为了让它正常工作,我必须创建一个自定义OnClickListener,它将视图作为参数,从那里我可以从视图中刮取元素

这不是一个优雅或好的解决方案;但它是有效的

    <TextView
        android:id="@+id/tvSurveyTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/surveyTitle" />

    <TextView
        android:id="@+id/tvSurveyShared"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="@string/surveyShared"
        android:layout_below="@+id/tvSurveyTitle"
        />

    <RadioGroup
        android:id="@+id/radioShared"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tvSurveyShared">

    <RadioButton
            android:id="@+id/radioButtonYes"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/yes"
            android:focusable="true"/>

        <RadioButton
            android:id="@+id/radioButtonNo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/no"
            android:focusable="true"/>

    </RadioGroup>

<TextView
        android:id="@+id/tvSurveyReason"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/surveyReason"
        android:layout_below="@+id/radioShared" />

    <TextView
        android:id="@+id/tvSurveyRating"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="@string/surveyRating"
        android:layout_below="@+id/tvSurveyReason" />

    <CheckBox
        android:id="@+id/checkBoxInterest"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/surveyInterestPositive"
        android:layout_below="@+id/tvSurveyRating"
        android:focusable="true" />

    <CheckBox
        android:id="@+id/checkBoxPrivacy"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/surveyShareLevelPositive"
        android:layout_below="@+id/checkBoxInterest"
        android:focusable="true" />

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/checkBoxPrivacy"
        android:focusable="true" />

    <View android:layout_width="fill_parent"
        android:layout_height="2dip"
        android:background="#FF00FF00"
        android:layout_below="@+id/ratingBar" />
    this.buttonSubmit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getData(v);submitSurvey();
        }
    });


public void getData(View view) {
//get data here
}

public void submitSurvey() {
    // Create a new HttpClient and Post Header
    String url;
    if(Singletons.Debug.debug) {
        url = "url for postback";
    } else {
        url = "url for postback";
    }

    NetworkAsyncTask nat = new NetworkAsyncTask();
    try {
        String response = nat.execute(url).get();
        //Log.d(TAG, "Response: " + response);
    } catch(ExecutionException e) {

    } catch(InterruptedException e) {

    }
}