In my app, it has two tabs, one is Reminder and the other is Completed Task.
When the toggle button is clicked, I want it move the list to Completed Task.
The idea are :
- Get the checked row id from sqlite
- Retrieve the data based on id from Reminder Table and insert into Completed Table.
- Call Retrieve method in Completed Tab.
But when I clicked the toggle button and swipe to Completed, it still empty. After I exit the app, and swipe to the Tab,only the data shown.
How can I made the data straight away show in Completed Tab when swipe instead of exit the app and re-open again ? Thanks
AllAdapter (Reminder)
holder.toggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((ToggleButton)v).isChecked()) {
int getPosition = (Integer) v.getTag(); // Here we get the position that we have set for the checkbox using setTag.
search.get(getPosition).setSelected(((ToggleButton) v).isChecked());
int id= search.get(getPosition).getID();
mdb = new MyDatabaseHelper(v.getContext());
database = mdb.getReadableDatabase();
Cursor cursor = database.rawQuery("SELECT * FROM " + MyDatabaseHelper.TABLE__TASK + " WHERE ID = ? ", new String[]{id+""}, null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String allTask = cursor.getString(cursor.getColumnIndex("Title"));
String name = cursor.getString(cursor.getColumnIndex("Name"));
String allTime = cursor.getString(cursor.getColumnIndex("Time"));
String allDate = cursor.getString(cursor.getColumnIndex("Date"));
insertDataToCompleteTab(id,name,allTask,allTime,allDate); // insert to another table
}
}
} else {
int getPosition = (Integer) v.getTag(); // Here we get the position that we have set for the checkbox using setTag.
search.get(getPosition).setSelected(((ToggleButton) v).isChecked());
}
}
});
CompletedTask
retrieveList(name);
public void retrieveList(String name) {
Toast.makeText(getActivity(),name,Toast.LENGTH_SHORT).show();
search.clear();
database = mdb.getReadableDatabase();
Cursor cursor = database.rawQuery("SELECT * FROM " + MyDatabaseHelper.TABLE_TASKCOMPLETED + " WHERE Name = ? ", new String[]{name}, null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int iD = cursor.getInt(cursor.getColumnIndex("ID"));
String allTask = cursor.getString(cursor.getColumnIndex("Title"));
String allTime = cursor.getString(cursor.getColumnIndex("Time"));
String allDate = cursor.getString(cursor.getColumnIndex("Date"));
if (adapter != null) {
adapter.add(iD, allTask, allTime, allDate);
listview.setAdapter(adapter);
adapter.getCount();
// check();
}
}
} else {
}
}
AllAdapter
Completed Tab
CompleteAdapter
android.support.v4.app.SuperNotCalledException: Fragment CompletedTask{41e4bca8 #1 id=0x7f0c005d android:switcher:2131492957:1} did not call through to super.onResume()
– Contemplate