I use the Expandable ListView , and the data in it is populated through the Sqlite database. I gave the option to remove the group from the ExpandableListView and actually removes the corresponding row in the database. But the activity is not updated, and the deleted "case" is displayed until one returns and returns to this activity . I created a class that extends *BaseExpandableListAdapter* . It contains all methods overridden . Below is the code:
public class ExpandableListAdapterForRunning extends BaseExpandableListAdapter { private Context _context; private List<String> _listDataHeader;
Now there is also the class RunningCase.java , which extends Activity . This class used to populate data in an ExpandableListView . OnLongClick() (tap and hold) of any group in ExpandableListView , a context menu will appear. context menu contains the Delete option to remove this case from the database and update RunningCase activity .
public class RunningCase extends Activity { String[] day; LinearLayout layout_MainMenu; Case cases; ExpandableListAdapterForRunning listAdapter; ExpandableListView expListView; List<String> listDataHeader; List<String> listDate; HashMap<String, List<String>> listDataChild; Case date; protected void onCreate(Bundle savedInstanceState) { prepareListData(); expListView=(ExpandableListView) findViewById(R.id.lvExp); listAdapter= new ExpandableListAdapterForRunning(this,listDataHeader,listDataChild,i,listDate); expListView.setAdapter(listAdapter); registerForContextMenu(expListView); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.add("Delete"); } @Override public boolean onContextItemSelected(MenuItem item) {
The db.getRunning() , db.getRunning_child() methods retrieve data from the database. In addition, the following code is code to remove from the database, which works fine:
void deletecase(String casenum){ SQLiteDatabase db = this.getWritableDatabase(); String whereClause = "Case_number = ?"; String[] whereArgs = new String[] { casenum }; db.delete(TABLE_CASEINFO,whereClause,whereArgs); db.delete(TABLE_CLIENTINFO,whereClause,whereArgs); db.delete(TABLE_DATEINFO,whereClause,whereArgs); Log.d("case deleted","casenum: "+casenum); db.close();
Please help me. activity should be updated when deleting a case to exclude an extra case. Thanks in advance!!
android expandablelistview notifydatasetchanged
ankul09jain
source share