简体   繁体   中英

Android How to refresh items in ExpandableListView

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

This is my Expandable list adapter's getChildView Method, I am using Sqlite database and I store data to database and need to delete some items also so i use onLongClickListener for Deleting items, when I long click on the item I want to delete a popup appears having delete button, when I click on that button the item from database deleted but the item still appears on that activity until I reopen the application, what I want is when I click on delete button it should be disappear from that list also immediately, Thanks in Advance,

You need to update the adapter for the view. Most adapter have the notifyDataSetChanged() method, which updates the data set it is displaying

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM