Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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_Sqlite - Fatal编程技术网

Android如何在ExpandableListView中刷新项目

Android如何在ExpandableListView中刷新项目,android,sqlite,Android,Sqlite,这是我的可扩展列表适配器的getChildView方法,我使用的是Sqlite数据库,我将数据存储到数据库,还需要删除一些项目,因此我使用onLongClickListener删除项目,当我长时间单击要删除的项目时,会出现一个带有删除按钮的弹出窗口,当我单击该按钮时,数据库中的项目已被删除,但在我重新打开应用程序之前,该项目仍显示在该活动中,我想要的是,当我单击“删除”按钮时,它也应立即从该列表中消失,提前感谢,您需要更新视图的适配器。大多数适配器都有notifyDataSetChanged()

这是我的可扩展列表适配器的getChildView方法,我使用的是Sqlite数据库,我将数据存储到数据库,还需要删除一些项目,因此我使用onLongClickListener删除项目,当我长时间单击要删除的项目时,会出现一个带有删除按钮的弹出窗口,当我单击该按钮时,数据库中的项目已被删除,但在我重新打开应用程序之前,该项目仍显示在该活动中,我想要的是,当我单击“删除”按钮时,它也应立即从该列表中消失,提前感谢,

您需要更新视图的适配器。大多数适配器都有
notifyDataSetChanged()
方法,该方法更新它正在显示的数据集

我调用dbcon.deleteData(children)方法下面的notifyDataSetChanged(),但不起作用
SQLController dbcon;
@Override
public View getChildView(int groupPosition, final int childPosition,
                     boolean isLastChild, View convertView, ViewGroup parent) {
final String children = (String) getChild(groupPosition, childPosition);
TextView text;
if (convertView == null) {
    convertView = inflater.inflate(R.layout.listrow_details, null);
}
text = (TextView) convertView.findViewById(R.id.textView1);
text.setText(children);
convertView.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        Toast.makeText(activity, children,Toast.LENGTH_SHORT).show();
    }
});

convertView.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View view) {

        AlertDialog.Builder Delete=new AlertDialog.Builder(activity);
        Delete.setTitle("Show Linups Or Delete");
        Delete.setMessage("Press Delete For Remove "+children+" or Press Show Lineups to get Lineups.");
        Delete.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
               dbcon=new SQLController(activity);
                dbcon.open();
                Cursor c=dbcon.returnData();
                if(c.moveToFirst())
                {
                    do{
                        if(children.equals(c.getString(0))){
                            dbcon.deleteData(children);
                            notifyDataSetChanged();
                            Toast.makeText(activity,"Successfully Deleted",Toast.LENGTH_LONG).show();
                            break;
                        }
                    }while(c.moveToNext());
                }
                dbcon.close();
            }
        }).show();
        return false;
    }
});
return convertView;
}