Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.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
Java 单击后如何从expandablelistview的列表中删除子项?_Java_Android_Expandablelistview - Fatal编程技术网

Java 单击后如何从expandablelistview的列表中删除子项?

Java 单击后如何从expandablelistview的列表中删除子项?,java,android,expandablelistview,Java,Android,Expandablelistview,所以我有一个可扩展的列表视图。在我单击了子项之后,它将从mysql表中删除数据。从表中删除数据后,我希望将其从列表中删除 我尝试使用remove(),但仍然不起作用。这是我的密码 exKonsumsi = (ExpandableListView) findViewById(R.id.EVkonsumsi_user); exKonsumsi.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); p

所以我有一个可扩展的列表视图。在我单击了子项之后,它将从mysql表中删除数据。从表中删除数据后,我希望将其从列表中删除

我尝试使用remove(),但仍然不起作用。这是我的密码

exKonsumsi = (ExpandableListView) findViewById(R.id.EVkonsumsi_user);
        exKonsumsi.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        prepareListMenuPagi();
        exKonsumsiAdapter = new com.ta.helper.ExpandableListAdapterKonsumsi(
                this, listDataHeaderDaftarAwal, listDataChildDaftarAwal);
        exKonsumsi.setAdapter(exKonsumsiAdapter);
        exKonsumsi.setOnChildClickListener(new OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                group = groupPosition;
                child = childPosition;


                String namaMakanan = listDataChildDaftarAwal.get(
                        listDataHeaderDaftarAwal.get(groupPosition)).get(
                        childPosition);

                Toast.makeText(getApplicationContext(), namaMakanan + "  " + "sudah dihapus" , Toast.LENGTH_LONG) .show();

                try {
                     String nama = URLEncoder.encode(username, "utf-8"); 
                     System.out.println(username);
                    String namatoEn = URLEncoder.encode(namaMakanan, "utf-8"); 
                    url += "?" + "&nama=" + nama + "&namatoEn=" + namatoEn ;
                    getRequest(url);
                 }
                    catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                listDataChildDaftarAwal.remove(namaMakanan);
                return true;
            }
        });
适配器:

public class ExpandableListAdapterKonsumsi extends BaseExpandableListAdapter {
    public static int takaran = 0;
    private Context context;
    private List<String> listDataHeader; // judul header
    private HashMap<String, List<String>> listDataChild; // child data dengan
                                                            // format judul
                                                            // header, judul
                                                            // child

    public ExpandableListAdapterKonsumsi(Context context,
            List<String> listDataHeader,
            HashMap<String, List<String>> listDataChild) {
        super();
        this.context = context;
        this.listDataHeader = listDataHeader;
        this.listDataChild = listDataChild;

    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        // TODO Auto-generated method stub
        return this.listDataChild.get(this.listDataHeader.get(groupPosition))
                .get(childPosition);
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        // TODO Auto-generated method stub
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final String childText = (String) getChild(groupPosition, childPosition);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(
                    R.layout.konsumsi_user_expand_listchild, null);
        }
        CheckedTextView listChild = (CheckedTextView) convertView
                .findViewById(R.id.lblListItemKonsumsi);
        listChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        // TODO Auto-generated method stub
        return this.listDataChild.get(this.listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        // TODO Auto-generated method stub
        return this.listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        // TODO Auto-generated method stub
        return this.listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        // TODO Auto-generated method stub
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(
                    R.layout.daftar_akun_expand_listgroup, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        // TODO Auto-generated method stub
        return true;
    }

}
公共类ExpandableListAdapter Konsumsi扩展了BaseExpandableListAdapter{
公共静态int takaran=0;
私人语境;
私有列表listDataHeader;//judul头
私有HashMap listDataChild;//子数据dengan
//格式朱杜尔
//朱杜尔头球
//孩子
公共可扩展列表适配器Konsumsi(上下文,
列表listDataHeader,
HashMap listDataChild){
超级();
this.context=上下文;
this.listDataHeader=listDataHeader;
this.listDataChild=listDataChild;
}
@凌驾
公共对象getChild(int-groupPosition,int-childPosition){
//TODO自动生成的方法存根
返回this.listDataChild.get(this.listDataHeader.get(groupPosition))
.get(儿童位置);
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
//TODO自动生成的方法存根
返回子位置;
}
@凌驾
公共视图getChildView(int-groupPosition、int-childPosition、,
布尔值isLastChild、视图转换视图、视图组父级){
//TODO自动生成的方法存根
最终字符串childText=(字符串)getChild(groupPosition,childPosition);
if(convertView==null){
LayoutInflater充气器=(LayoutInflater)this.context
.getSystemService(上下文布局\充气机\服务);
convertView=充气机。充气(
R.layout.konsumsi_user_expand_listchild,null);
}
CheckedTextView listChild=(CheckedTextView)convertView
.findviewbyd(R.id.lblListItemKonsumsi);
setText(childText);
返回视图;
}
@凌驾
公共整数getChildrenCount(整数组位置){
//TODO自动生成的方法存根
返回this.listDataChild.get(this.listDataHeader.get(groupPosition))
.size();
}
@凌驾
公共对象getGroup(int-groupPosition){
//TODO自动生成的方法存根
返回此.listDataHeader.get(groupPosition);
}
@凌驾
public int getGroupCount(){
//TODO自动生成的方法存根
返回此.listDataHeader.size();
}
@凌驾
公共长getGroupId(int-groupPosition){
//TODO自动生成的方法存根
返回组位置;
}
@凌驾
公共视图getGroupView(int-groupPosition,布尔值isExpanded,
视图(视图、视图组父级){
//TODO自动生成的方法存根
字符串头文件=(字符串)getGroup(groupPosition);
if(convertView==null){
LayoutInflater infalInflater=(LayoutInflater)this.context
.getSystemService(上下文布局\充气机\服务);
convertView=infalInflater.充气(
R.layout.daftar_akun_expand_listgroup,null);
}
TextView lblistheader=(TextView)convertView
.findviewbyd(R.id.lblistheader);
lblListHeader.setTypeface(null,Typeface.BOLD);
lblListHeader.setText(标题);
返回视图;
}
@凌驾
公共布尔表ID(){
//TODO自动生成的方法存根
返回false;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
//TODO自动生成的方法存根
返回true;
}
}

任何帮助都将不胜感激。谢谢

您必须删除与listview项目相关的数据,例如删除
listDataChild
中的项目之一,并调用
适配器。notifydatasetchanged
通知listview数据已更改,然后listview将刷新视图以与数据保持同步