Java Android:使用多行布局获取listview的值

Java Android:使用多行布局获取listview的值,java,android,listview,android-fragments,Java,Android,Listview,Android Fragments,我有一个具有多行布局(广播组、编辑文本、文本视图)的列表视图,具有多选模式。我想在提交按钮上检索它的选定数据(用户选定或键入的数据) 这是我的主文件中的代码: public class GraduatingSurvey extends Fragment { private static final String LOGTAG = "log" ; public String stdcode = "024-15-16079"; Button submit; Rad

我有一个具有多行布局(广播组、编辑文本、文本视图)的列表视图,具有多选模式。我想在提交按钮上检索它的选定数据(用户选定或键入的数据)

这是我的主文件中的代码:

public class GraduatingSurvey extends Fragment {


    private static final String LOGTAG = "log" ;
    public String stdcode = "024-15-16079";
    Button submit;
    RadioGroup radioGroup;
    RadioButton radioButton;
    EditText comment;

    ArrayList<GraduatingSurveyModel> graduatingModelList;
    ListView listView;
    View view;

    public GraduatingSurvey() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view =  inflater.inflate(R.layout.fragment_graduating_survey, container, false);
        submit = (Button) view.findViewById(R.id.btn_graduate_submit);
        listView = (ListView) view.findViewById(R.id.graduate_list);
        graduatingModelList = new ArrayList<GraduatingSurveyModel>();

        //handle submit form Event.
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final int child=listView.getAdapter().getCount();
                Log.i("radio", "child: " + child);
                SparseBooleanArray checked = listView.getCheckedItemPositions(); //Is returning empty
                Log.i("radio", "sparseArray: " + checked);
                for(int i=0;i<child;i++) {
                    int type = listView.getAdapter().getItemViewType(i);
                    Log.i("radio", "type: " + type);
                    if(type == 2){
                        // Want to retrieve data here

                    }
                    if(type == 0)
                    {

                    }
                    if(type == 1){

                    }

                }

            }
        });

        NetAsync(view);
        return view;
    }
这是主要片段的XML布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    android:background="@color/dialog_background"
    android:orientation="vertical"
    tools:context="iulms.iunc.edu.pk.iqraiulms.GraduatingSurvey"
    android:id="@+id/main_layout">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/graduate_list"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_above="@+id/btn_graduate_submit"
        />
    <Button
        android:id="@+id/btn_graduate_submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="submit"
        android:layout_alignParentBottom="true"
        />
</RelativeLayout>

这些是listview中不同类型行的布局

行类型1:

<?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="match_parent"
    android:background="@color/dialog_background"
    android:orientation="vertical"
    android:paddingBottom="16dp"
    android:paddingTop="16dp">

    <TextView
        android:id="@+id/graduate_question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:text="1. Here comes questions?"
        android:textSize="13dp" />

   <!-- <EditText
        android:id="@+id/graduate_comment"
        style="@style/GraduateTextBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:background="@drawable/textbox"
        android:ems="10"
        android:hint="Comment"
        android:inputType="textMultiLine"
        android:lines="3" />-->

    <LinearLayout
        android:id="@+id/graduate_choices"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RadioGroup
            android:id="@+id/graduate_radioGroup"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RadioButton
                android:id="@+id/graduate_sAgree"
                style="@style/GraduateRadioButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/checkbox_selector"
                android:button="@android:color/transparent"
                android:checked="false"
                android:text="Strongly Agree" />

            <RadioButton
                android:id="@+id/graduate_agree"
                style="@style/GraduateRadioButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/checkbox_selector"
                android:button="@android:color/transparent"
                android:checked="false"
                android:text="Agree" />

            <RadioButton
                android:id="@+id/graduate_uncertain"
                style="@style/GraduateRadioButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/checkbox_selector"
                android:button="@android:color/transparent"
                android:checked="false"
                android:text="Uncertain"
                />

            <RadioButton
                android:id="@+id/graduate_disagree"
                style="@style/GraduateRadioButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/checkbox_selector"
                android:button="@android:color/transparent"
                android:checked="false"
                android:text="Disagree" />

            <RadioButton
                android:id="@+id/graduate_sDisagree"
                style="@style/GraduateRadioButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/checkbox_selector"
                android:button="@android:color/transparent"
                android:checked="false"
                android:text="Strongly Disagree" />
        </RadioGroup>
    </LinearLayout>
</LinearLayout>

行类型2

<?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="match_parent"
    android:background="@color/dialog_background"
    android:orientation="vertical"
    android:paddingBottom="16dp"
    android:paddingTop="16dp">

    <TextView
        android:id="@+id/graduate_question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:text="1. Here comes questions?"
        android:textSize="13dp" />

    <EditText
        android:id="@+id/graduate_comment"
        style="@style/GraduateTextBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:background="@drawable/textbox"
        android:ems="10"
        android:hint="Comment"
        android:inputType="textMultiLine"
        android:lines="3" />
    </LinearLayout>

行类型3:

<?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="match_parent"
    android:background="@color/dialog_background"
    android:orientation="vertical"
    android:paddingBottom="16dp"
    android:paddingTop="16dp">

    <TextView
        android:id="@+id/graduate_question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dp"
        android:text="1. Here comes questions?"
        android:textSize="15dp"
        android:textColor="@color/primary_dark"/>
</LinearLayout>

如何检索主片段中提交的数据


感谢您的帮助,您可以创建一个自定义类,其行值如下:

Arraylist<CustomClass> mnewList = new ArrayList();
Class CustomClass
{
    private String edValues,
    private int rowId,
}
Arraylist mnewList=new Arraylist();
类自定义类
{
私有字符串值,
私人int rowId,
}
等等


然后在“将当前选定的项添加/删除到自定义列表”中的单选按钮上实现“更改侦听器”。

为此,您可以创建一个具有行值的自定义类,如

Arraylist<CustomClass> mnewList = new ArrayList();
Class CustomClass
{
    private String edValues,
    private int rowId,
}
Arraylist mnewList=new Arraylist();
类自定义类
{
私有字符串值,
私人int rowId,
}
等等


然后在“添加/删除当前选定项目到自定义列表”中的“更改侦听器”单选按钮上实现。

谢谢。你能再解释一下吗。我是android开发新手。我正在做一项调查,调查中提出了不同的问题。有些问题可以通过选择单选按钮来回答,有些问题可以通过发表评论来回答。这是我创造的。现在我想要的是,当用户按下submit按钮时,我想要收集所有选中的单选按钮和注释,并将它们发布到服务器。如何在提交时单击。listView.GetCheckEditePositions()返回一个空数组。谢谢。你能再解释一下吗。我是android开发新手。我正在做一项调查,调查中提出了不同的问题。有些问题可以通过选择单选按钮来回答,有些问题可以通过发表评论来回答。这是我创造的。现在我想要的是,当用户按下submit按钮时,我想要收集所有选中的单选按钮和注释,并将它们发布到服务器。如何在提交时单击。listView.GetCheckEditePositions()返回一个空数组。
Arraylist<CustomClass> mnewList = new ArrayList();
Class CustomClass
{
    private String edValues,
    private int rowId,
}