Android如何刷新ExpandableListView中的项目

时间:2014-04-17 15:49:09

标签: android sqlite

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;
}

这是我的可扩展列表适配器的getChildView方法,我正在使用Sqlite数据库并且我将数据存储到数据库并且还需要删除一些项目所以我使用onLongClickListener来删除项目,当我长按项目时我想要删除一个弹出窗口显示有删除按钮,当我点击该按钮时,该项目从数据库中删除但该项目仍然出现在该活动上,直到我重新打开该应用程序,我想要的是当我点击删除按钮时它应该从该列表也立即,在此先感谢,

1 个答案:

答案 0 :(得分:0)

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