Android 每个元素都带有 editText 和复选框的列表视图

Android listview with editText and checkbox for each element

假设我有一个项目列表,我想为每个项目构建一个表单。此表单由两个复选框和一个 editText 组成。例如,我想知道每个项目是否存在于仓库中及其数量。我正在考虑使用 listview 来解决我的问题,其中 listview 的每个元素都将包含一个项目的名称、两个复选框和一个 editText。
问题是我知道的 listview 的唯一用途是呈现元素列表,我不知道如何用它解决我的问题(我是 android 的初学者)。有人可以帮助我吗?
还有其他方法可以解决我的问题吗?
谢谢

尝试实现自定义 ListView 适配器!这比您想象的要容易!

首先您需要创建布局来代表列表中的每个项目:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Test TEST" />

<LinearLayout android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignBottom="@id/itemTextView"
    android:layout_alignParentRight="true">
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/doneCheckBox" />
</LinearLayout>

然后在您的代码中实现自定义适配器:

public CusomAdapter(Context mainContex, YourItems<SomeItem> someItems) {
    this.mainContex = mainContex;
    this.someItems = someItems;
}

@Override
public int getCount() {
    return someItems.size();
}

@Override
public Object getItem(int position) {
    return someItems.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {


    View item = convertView;
    if (item == null) {
        item = LayoutInflater.from(mainContex).inflate(R.layout.shoplist_item, null); // your listView layout here!
    }

     //fill listView item with your data here!
    //initiate your check box
    CheckBox doneCheckBox = (CheckBox)item.findViewById(R.id.doneCheckBox);

    //add a checkbox listener
    doneCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
         if(isChecked){
            doneCheckBox.ischecked=true;
        }
        else{
            doneCheckBox.ischecked=false;
        }
    }
});

    return item;
}

不要忘记在 Activity 布局中添加 ListView 元素!