Android Studio how to update ListView after updating the DB in the cursor by pressing the button?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
11 views
This piece of code snippet with the list, there is a button btnStopAllTask changes the status of the task. Everything works fine and the list is updated(I know why, just every time be re-created adapter).
BtnStopAllTask Button = (Button) view.findViewById(R. id.buttonStopAllTask); btnStopAllTask.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { contentValues.put(DBHelper.STATUS statusOff); database.update(DBHelper.TABLE_TASKS, contentValues, DBHelper.STATUS + "=" + String.valueOf(statusStart), null); onResume(); } }); //final View viewTimer = getLayoutInflater().inflate(R. layout.timer, null); return view; } public void onResume() { super.onResume(); dbHelper = new DBHelper(getContext()); database = dbHelper.getReadableDatabase(); userCursor = database.rawQuery("select * from" + DBHelper.TABLE_TASKS + "where" + DBHelper.STATUS + "=?", new String[]{String.valueOf(statusStart)}); userCursor.moveToNext(); String[] headers = new String[]{DBHelper.NAME DBHelper.DURATION_TASK}; adapter = new CustomCursorAdapter(getContext(), R. layout.timer userCursor, headers, new int[]{R. id.textViewNameTask, R. id.textViewWithTimer}, 0); lvWithTaskIsRunningNow.setAdapter(adapter); adapter.notifyDataSetChanged(); } public void onDestroy() { super.onDestroy(); database.close(); userCursor.close(); }

This part of the code of custom adapter (public class CustomCursorAdapter extends SimpleCursorAdapter)
If you launch via intent it works, but the constant restarting activiti hate(blink+ delay)
Tell me plez. how to dynamically update the list after pressing the button(buttons are processed in the adapter )??
public void bindView(View View, final Context _context, final Cursor _cursor) { super.bindView(view,_context,_cursor); TvWithNameTask TextView = (TextView) view.findViewById(R. id.textViewNameTask); TvWithTimer TextView= (TextView) view.findViewById(R. id.textViewWithTimer); ImageButton btnStop = (ImageButton) view.findViewById(R. id.imageButtonStop); ImageButton btnStart= (ImageButton) view.findViewById(R. id.imageButtonStart); ImageButton btnPause= (ImageButton) view.findViewById(R. id.imageButtonPause); contentValues = new ContentValues(); dbHelper = new DBHelper(_context); database = dbHelper.getWritableDatabase(); btnStop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int keyId = _cursor.getInt(_cursor.getColumnIndex(DBHelper.KEY_ID)); contentValues.put(DBHelper.STATUS IsRunningNow.statusOff); database.update(DBHelper.TABLE_TASKS, contentValues, DBHelper.KEY_ID + "=" + String.valueOf(keyId), null); //swapCursor(_cursor); /* Intent intent = new Intent(_context, MainActivity.class); _context.startActivity(intent);*/ } });
by | 11 views

1 Answer

0 like 0 dislike
If you are using a listview I recommend postert towards ContentProvider
by

Related questions

0 like 0 dislike
3 answers
asked Mar 29, 2019 by maeln0r
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,405 users