我想利用 expandlelistView 来显示产品和子产品

我想利用 expandlelistView 来显示产品和子产品,即子持有者,在子持有者中,它包含一个 textView 和一个 Edittext,它保存每个子产品的产品计数值,这里的问题是这个。

  1. 当我在编辑文本中输入值时,在折叠组时,编辑文本中的数据会丢失。

  2. 这些值将在其他组编辑文本中重复。

3.如何保存数据以供以后在应用程序中使用。

下面的代码。

活动布局。

<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"

tools:context=".ui.activities.ShelfCheckActivity">



<ExpandableListView

    android:id="@+id/listview"

    android:layout_width="wrap_content"

    android:layout_height="match_parent"

    android:dividerHeight="0dp"

    android:groupIndicator="@null"

    android:descendantFocusability="beforeDescendants"/>


</RelativeLayout>

模型类


public class ListItemModel {


String title;

ArrayList<EdittextValues> arrayList = new ArrayList<>();


public ListItemModel(String title) {

    this.title = title;

}


public String getTitle() {

    return title;

}


public void setTitle(String title) {

    this.title = title;

}


public ArrayList<EdittextValues> getArrayList() {

    return arrayList;

}


public void setArrayList(ArrayList<EdittextValues> arrayList) {

    this.arrayList = arrayList;

}

}

波霍类


public class EdittextValues {

String value;


public EdittextValues(String value) {

    this.value = value;

}


public String getValue() {

    return value;

}


public void setValue(String value) {

    this.value = value;

}

}


扬帆大鱼
浏览 81回答 1
1回答

鸿蒙传说

只需更改以下方法并检查其工作与否!@Overridepublic View getChildView(int groupPosition, int childPosition, boolean&nbsp;&nbsp; &nbsp; isLastChild, View convertView, ViewGroup parent) {&nbsp; &nbsp; if(convertView == null)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; convertView = LayoutInflater.from(context).inflate(R.layout.list_row_child,null);&nbsp; &nbsp; &nbsp; &nbsp; childViewHolder = new ChildViewHolder(convertView, groupPosition, childPosition);&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; convertView.setTag(childViewHolder);&nbsp; &nbsp; }&nbsp; &nbsp; else{&nbsp; &nbsp; &nbsp; &nbsp; childViewHolder = (ChildViewHolder) convertView.getTag();&nbsp; &nbsp; }&nbsp; childViewHolder.childTitle.setText(groupItem.get(groupPosition)&nbsp;.getChildTitles().get(childPosition));&nbsp; &nbsp; &nbsp; return convertView;}另一个变化是private class ChildViewHolder {&nbsp; &nbsp; public TextView childTitle;&nbsp; &nbsp; public EditText et;&nbsp; &nbsp; public ChildViewHolder(View itemView, int groupPosition, int childPosition) {&nbsp; &nbsp; &nbsp; &nbsp; super(itemView);&nbsp; &nbsp; &nbsp; &nbsp; childTitle = itemView.findViewById(R.id.textViewChild);&nbsp; &nbsp; &nbsp; &nbsp; et = itemView.findViewById(R.id.productCount);&nbsp; &nbsp; &nbsp; &nbsp; et.addTextChangedListener(new TextWatcher() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(charSequence != null){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; groupItem.get(groupPosition).getArrayList().get(childPosition).setValue(charSequence.toString());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void afterTextChanged(Editable editable) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java