Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.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
Android 从我的适配器中刷新ExpandableListView_Android_Expandablelistview_Notifydatasetchanged - Fatal编程技术网

Android 从我的适配器中刷新ExpandableListView

Android 从我的适配器中刷新ExpandableListView,android,expandablelistview,notifydatasetchanged,Android,Expandablelistview,Notifydatasetchanged,我只发现了一个类似的问题,它对我没有帮助。我希望你能帮助我,因为我被困住了 这是我的自定义适配器(仅适用于相关部分): MyExpandableListAdapter: public class MyExpandableListAdapter extends BaseExpandableListAdapter { //... @Override public View getChildView(int groupPosition, int childPosition,

我只发现了一个类似的问题,它对我没有帮助。我希望你能帮助我,因为我被困住了

这是我的自定义适配器(仅适用于相关部分):

MyExpandableListAdapter

public class MyExpandableListAdapter extends BaseExpandableListAdapter {

    //...

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View view, ViewGroup parent) {     
        ChildInfo childInfo = (ChildInfo) getChild(groupPosition, childPosition);
        if (view == null) {
            LayoutInflater infalInflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = infalInflater.inflate(R.layout.prisustva_detaljno_child_row,
                    null);
        }

        Button delete = (Button) view.findViewById(R.id.delete);
        delete.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                RelativeLayout Rl = (RelativeLayout) v.getParent();
                TextView id = (TextView) Rl.findViewById(R.id.id_prisustvo);
                PrisustvaAdapter deleteByID = new PrisustvaAdapter(context);

                deleteByID.openToWrite();
                deleteByID.openToRead();
                deleteByID.deleteID(id .getText().toString());
                deleteByID.close();

                Toast.makeText(context, "Successfully deleted!",
                        Toast.LENGTH_LONG).show();
            }
        });

        // ...
        return view;
    }

// ...
}
你可以看到,我的
ExpandableListView
的每个子行中都有一个按钮。当我单击该按钮时,它会触发数据库中的删除过程,您也可以看到,我必须从适配器中进行删除,因为只有在适配器中,我才能为子行中的按钮创建单击事件。我想知道从数据库中删除数据时如何刷新我的
ExpandableListView
?我必须从适配器内部执行此操作吗?如果没有,还有什么选择


注:如果你们还需要更多的代码,请告诉我。

我不能肯定没有看到剩下的代码(你如何实例化你的
BaseExpandableAdapter
),但是在你的
onClick()
方法的末尾调用
notifyDatasetChanged()
应该可以做到这一点。

我已经尝试过了,但没有成功。删除子行后不应该调用
notifyDatasetChanged()
。因为我只是从数据库中删除它,而不是从列表中删除。当我使用ListView时,我使用了这个方法
adapter.remove()
adapter.add()
,之后我调用了
notifyDatasetChanged()
,它工作起来很有魅力,但我无法使用ExpandableListView来理解它。如果您的适配器基于列表(而不是数据库),您必须将其从列表中删除,然后调用notifyDataSetChanged()。我在了解如何从列表中删除特定项后对其进行了管理。这是我唯一的问题,而且很简单。谢谢你的提示,帮了我很多忙。另外,我有一个ArrayList的ArrayList,我和LinkedHashMap链接。起初我不知道如何从那里得到具体的商品。但最后很简单。