例如,我有一個編輯文本和一個按鈕。當按下按鈕時,文本將添加到我的可擴展列表視圖中的第一個組,並且每個以下項目都將添加到其下方。謝謝。 (如果您需要的代碼我到目前爲止請請求。)如何將子項動態添加到可展開的列表視圖中。
2
A
回答
5
第一個你應該創建你的自定義適配器。 曾經創建過這樣的類。
public class ExpandableListParentClass{
private Object parent;
private ArrayList<Object> parentChildren;
public ExpandableListParentClass() {
}
public ExpandableListParentClass(Object parent, ArrayList<Object> parentChildren) {
this.parent = parent;
this.parentChildren = parentChildren;
}
public Object getParent() {
return parent;
}
public void setParent(Object parent) {
this.parent = parent;
}
public ArrayList<Object> getParentChildren() {
return parentChildren;
}
public void setParentChildren(ArrayList<Object> parentChildren) {
this.parentChildren = parentChildren;
}
}
,並創建您的適配器
public class ExpandableListAdapter extends BaseExpandableListAdapter implements Filterable{
private LayoutInflater inflater;
private ArrayList<ExpandableListParentClass<Object>> mParent;
private View view;
public ArrayList<Object> getMParent() {
return mParent;
}
public ExpandableListAdapter(Context context,
ArrayList<ExpandableListParentClass<Object>> parentList) {
this.mParent = parentList;
this.inflater = LayoutInflater.from(context);
}
// counts the number of group/parent items so the list knows how many
// times calls getGroupView() method
public int getGroupCount() {
return mParent.size();
}
// counts the number of children items so the list knows how many times
// calls getChildView() method
public int getChildrenCount(int parentPosition) {
int size =0;
if(mParent.get(parentPosition).getParentChildren() != null){
size = mParent.get(parentPosition).getParentChildren().size();
}
return size;
}
// gets the title of each parent/group
public Object getGroup(int i) {
return mParent.get(i).getParent();
}
// gets the name of each item
public Object getChild(int parentPosition, int childPosition) {
return mParent.get(parentPosition).getParentChildren().get(childPosition);
}
public long getGroupId(int parentPosition) {
return parentPosition;
}
public long getChildId(int i, int childPosition) {
return childPosition;
}
public boolean hasStableIds() {
return true;
}
// in this method you must set the text to see the parent/group on the list
public View getGroupView(int parentPosition, boolean b, View view, ViewGroup viewGroup) {
if (view == null) {
view = inflater.inflate(R.layout.layout_listview, viewGroup, false);
}
return view;
}
// in this method you must set the text to see the children on the list
public View getChildView(int parentPosition, int childPosition, boolean b, View view, ViewGroup viewGroup) {
if (view == null) {
view = inflater.inflate(R.layout.layout_listview, viewGroup, false);
}
// return the entire view
return view;
}
public boolean isChildSelectable(int i, int i1) {
return true;
}
}
now fill to list
List<ExpandableListParentClass> arrayParents = new ArrayList<ExpandableListParentClass>();
ExpandableListParentClass item = new ExpandableListParentClass();
item.setParent(yourParentItem);
item.setParentChildren(yourChildList);
後
當你需要添加子
ExpandableListView myExpList= (ExpandableListView) this.view.findViewById(R.id.yourExpListView);
ExpandableListAdapter adapter =
(ExpandableListAdapter) myExpList.getExpandableListAdapter();
((ExpandableListParentClass)adapter.getMParent().get(0)).getParentChildren().add(object);
//(change to get(0) which you parent want to get)
adapter.notifyDataSetChanged();
adapter.notifyDataSetInvalidated();
相關問題
- 1. 如何將android可展開列表視圖添加到mapview ..?
- 2. 將子項添加到列表視圖
- 3. 展開可展開列表視圖中的所有子項
- 4. 將頁腳添加到可展開的列表視圖
- 5. 如何在Monodroid中動態添加項目到列表視圖
- 6. 如何在winforms中動態添加項目到列表視圖
- 7. 動態添加組和標題到可擴展列表視圖
- 8. 如何動態添加子項目onClick在父項目可擴展列表視圖在android中?
- 9. 如何將標題行添加到使用simplecursortreeadapter的可擴展列表視圖的子視圖列表
- 10. 將項目動態添加到列表視圖頂部
- 11. 將動態項目添加到列表視圖
- 12. 將項目添加到列表視圖動態android
- 13. 將選中的項目移動到可擴展列表視圖
- 14. 動態項目添加到列表視圖中的Windows8
- 15. 將空項添加到列表視圖
- 16. 將項目添加到列表視圖
- 17. 如何動態添加背景視圖到Recycler列表視圖項目?
- 18. 將新添加的項添加到我的列表視圖中?
- 19. 在jQuery Mobile中動態添加項目到列表視圖
- 20. 我如何將可擴展列表視圖子項插入到sqlite中?
- 21. 如何將行動添加到可擴展列表中的每個孩子?
- 22. 如何在可擴展列表視圖中添加圖像?
- 23. 如何將圖標添加到Adobe Flex移動項目中的視圖列表
- 24. 如何將項目添加到列表視圖中?
- 25. 動態添加項目到列表視圖(jQuery Mobile的)
- 26. 動態添加不同佈局的項目到列表視圖
- 27. 在單選按鈕列表中動態添加子列表視圖項目
- 28. 可擴展列表視圖滾動到列表視圖中
- 29. 如何在Android中創建具有動態多子視圖的可展開列表視圖
- 30. 如何將兩個文字瀏覽添加到可擴展列表視圖的子項
我stuckeed here.Can您分享您的代碼嗎? – Niroj 2016-09-26 04:18:30