Я получаю уведомления от firebase, которые я сохраняю в MySqli. Когда я получаю уведомление, я подписываюсь на изменения в моем основном приложении. Так что у меня есть listView, который я заполняю из курсора, все работает здесь хорошо. Затем я отображаю результаты - тоже все ок. Теперь я хотел бы иметь анимацию смахивания (также работает). Моя проблема заключается в том, когда я сильно ударяю представление не refre sh. Я пытался использовать simpleCursorAdapter.notifyDataSetChanged (); также я попробовал swapCursor, где перед этим я вызвал Cursor newCursor = dbManager.getOpenNotifications () и затем передал его в simpleCursorAdapter.swapCursor (newCursor). Я впервые занимаюсь курсорами. Я прочитал все открытые вопросы и искал все еще, но я не могу найти решение. Может быть, я упускаю что-то очевидное или моя концепция и недооценка неверны?
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("newData"));
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_workplace);
relativeLayout = findViewById(R.id.bottomRelative);
listView = findViewById(R.id.mainWorkspaceList);
dbManager = new DBManager(this);
dbManager.open();
getOpenNotifications();
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
new IntentFilter("newData"));
}
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
getOpenNotifications();
}
};
@SuppressLint("ClickableViewAccessibility")
public void getOpenNotifications(){
dbManager = new DBManager(this);
dbManager.open();
cursor = dbManager.getOpenNotifications();
int i = dbManager.getCountOfActive();
String countActive = String.valueOf(i);
setNotificationsWaiting = findViewById(R.id.xPending);
setNotificationsWaiting.setText(String.valueOf(arraySize));
if (countActive.equals("0")){
setNotificationsWaiting.setText("0");
//todo .. load another layout
}else {
setNotificationsWaiting.setText(countActive);
messages = new String[] { DatabaseHelper.Position, DatabaseHelper.FullName };
final int [] toView = new int []{R.id.positionText, R.id.playersName};
simpleCursorAdapter = new SimpleCursorAdapter(this, R.layout.notifications_view, cursor, messages, toView, 0);
listView.setAdapter(simpleCursorAdapter);
//klicanje funkcije za left / right
listView.setOnTouchListener(new OnSwipeTouchListener(this, listView) {
@Override
public boolean onSwipeRight(int pos) {
View viewItem = listView.getChildAt(pos);
slideOutRight(viewItem);
final int testPos = cursor.getPosition();
cursor.moveToPosition(testPos);
int i = cursor.getColumnIndex("position");
int po = cursor.getInt(i);
String position = Integer.toString(po);
Log.i("rokane", position);
dbManager.updatePosition(position,"3");
simpleCursorAdapter.notifyDataSetChanged();
/* final int testPos = cursor.getPosition();
cursor.moveToPosition(testPos);
int i = cursor.getColumnIndex("position");
int po = cursor.getInt(i);
String position = Integer.toString(po);
Log.i("rokane", position);
dbManager.updatePosition(position,"3");
updateUI();*/
return true;
}