UPDATE : I am able to replicate this issue every time on my Galaxy S2 (with and without debugging mode), but never on the Emulator!
Я использую контекстное меню в ListView
(который использует пользовательскую реализацию CursorAdapter
), чтобы пользователь мог выбрать опцию « Удалить все ». Когда этот параметр выбран, все элементы, отображаемые в списке, должны быть удалены постоянно из базы данных, после чего следует вызвать changeCursor (..)
на адаптере, чтобы заставить список обновляться ,
Однако происходит то, что даже после удаления записей из базы данных и вызова changeCursor (..)
элементы видны. Только разделители элементов исчезают. Только после того, как я прикоснусь к списку, очистите эти элементы.
When the user activates the context menu :
http://i.stack.imgur.com/ivFvJ.png
After deletion from database AND calling changeCursor(..)
:
http://i.stack.imgur.com/CX6BM.png
У меня возникла другая проблема с ListView ( элементы списка ListView на Android во время прокрутки ), и я использую тот же ListView, так что, возможно, проблемы связаны? Есть ли какой-то шаг, чтобы заставить ListView
перерисовывать после обновления базы данных? Или это не происходит автоматически из-за ошибки в том, как я реализовал решение? Заранее спасибо!
Here's the xml for the ListView
Here's the newView(..)
method of my custom CursorAdapter
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.view_list_item, parent, false);
return view;
}
The bindView(..)
method of my CursorAdapter
public void bindView(View view, Context context, Cursor cursor) {
TextView whatTextView = (TextView) view.findViewById(R.id.item_what_text);
whatTextView.setText(cursor.getString(1));
TextView whenTextView = (TextView) view.findViewById(R.id.item_when_text);
if(cursor.getInt(9) != 0)//DONE_FLAG = 1 (completed)
{
//Arrow visibility
ImageView arrow = (ImageView)view.findViewById(R.id.list_item_arrow);
arrow.setVisibility(View.INVISIBLE);
//Text color
whatTextView.setTextColor(Color.LTGRAY);
whenTextView.setTextColor(Color.LTGRAY);
//WHEN text
whenTextView.setText(TimeCalculationHelper.getCompletedTimeString(cursor.getLong(2)));
}
else//DONE_FLAG = 0
{
//Arrow visibility
ImageView arrow = (ImageView)view.findViewById(R.id.list_item_arrow);
arrow.setVisibility(View.VISIBLE);
//Text color
whatTextView.setTextColor(Color.BLACK);
whenTextView.setTextColor(Color.BLACK);
//WHEN text
whenTextView.setText(TimeCalculationHelper.getTimeRemainingString(cursor.getLong(2)));
}
}
Here's my onContextItemSelected(..)
method from the Activity
that contains the ListView
public boolean onContextItemSelected(MenuItem item)
{
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
ListView allRemindersList = (ListView)findViewById(R.id.all_reminders_list);
switch (item.getItemId()) {
case R.id.delete_item:
//Delete the selected reminder from the database
databaseHelper.deleteRowByID(info.id);
//Refresh the main activity list
((ActiveRemindersAdapter) allRemindersList.getAdapter()).changeCursor(databaseHelper.getAllRemindersForList());
return true;
case R.id.delete_done:
//Delete all reminders with DONE_FLAG = 1
databaseHelper.deleteDoneReminders();
//Refresh the main activity list
((ActiveRemindersAdapter) allRemindersList.getAdapter()).changeCursor(databaseHelper.getAllRemindersForList());
}
return false;
}