所以当我注意到一些奇怪的东西时,我正在实现创建,删除和更新到我的应用程序中。这是我的情况:
图表A:
如果我创建了一个'注意'然后使用其ID作为唯一(警报和通知)设置警报并通知它,然后尝试删除它(以及取消),不会发生任何事情。通知仍然存在,但我的日志显示已取消取消方法。
图表B:
如果我重新启动应用(退出然后返回) 注释仍然存在。如果我将其删除然后,通知消失。如果我尝试重新启动它,则会完全删除。
DeleteItem方法:
public void deleteItem(final int position, final RecyclerView rv) {
Log.d("RecyclerView", "deleteItem method called at: " + position + " on " + data.get(position).getTitle() + " of ID " + data.get(position).getID());
// BUG position is the same - identical titles called - funky titles appearing from other positions
// BUG Other snackbar showing causes dismissal of original Snackbar and deletes note
final Info currentNote = data.get(position);
final int originalPosition = position;
data.remove(position);
// Removes Info object at specified position
// notifyDataSetChanged();
notifyItemRemoved(position);
// Notifies the RV that item has been removed
/* HOW DOES ALL THIS WORK??
As an ArrayList that contains all Info objects has been created in RecyclerAdapter,
calling the delete method and passing data.get(position) returns the Info object at that position
as every Info object is set in order to the RV item, which makes deleteNote in DB work
*/
Snackbar snackbar = Snackbar.make(rv, "Note Forgotten!", Snackbar.LENGTH_LONG)
// .make(View where Snackbar is shown, Message on Snackbar, LENGTH_INDEFINITE means Snackbar is shown until dismissed manually)
// NOTE If not wrapped in COORDINATORLAYOUT, SWIPE TO DISMISS DOES NOT WORK
.setAction("UNDO", new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("RV Adapter", "Note replaced on: " + currentNote.getTitle());
Snackbar.make(rv, "Note replaced!", Snackbar.LENGTH_LONG).show();
data.add(originalPosition, currentNote);
notifyItemInserted(originalPosition);
}
});
// Customizing Snackbar
// Changing message text color
snackbar.setActionTextColor(Color.RED);
// Changing action button text color
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.YELLOW);
snackbar.setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
switch (event) {
case DISMISS_EVENT_ACTION:
// Snackbar was dismissed via click on action button
break;
case DISMISS_EVENT_SWIPE:
// Snackbar was dismissed via manual swipe
break;
case DISMISS_EVENT_MANUAL:
// Snackbar was dismissed via dismiss() method called
break;
case DISMISS_EVENT_CONSECUTIVE:
// Snackbar was dismissed via another Snackbar being shown
break;
case DISMISS_EVENT_TIMEOUT:
Log.d("RV Adapter", "Note deleted on: " + currentNote.getTitle());
// Snackbar was dismissed via timeout
DBInfo dbInfo = new DBInfo(context);
dbInfo.deleteNote(currentNote);
// Deletes RV item/position's Info object
boolean alarmSet = (PendingIntent.getBroadcast(context, currentNote.getID(),
new Intent(context, AlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT) != null);
Log.d("RecyclerAdapter", "Item: " + currentNote.getTitle() + " of ID: " + currentNote.getID() + " has Alarm Set value of " + alarmSet);
// if statement to determine if there is an alarm set
if (alarmSet) {
// Cancel Alarm
// Get intent originally used to invoke AlarmReceiver.class
Intent cancelIntent = new Intent(context, AlarmReceiver.class);
cancelIntent.putExtra("Purpose", "Cancel Alarm");
Log.d("RecyclerAdapter", "PendingIntent cancelled of ID: " + currentNote.getID());
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, currentNote.getID(), cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Grab same PendingIntent that was used to set Alarm
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
Log.d("RecyclerAdapter", "Alarm Cancelled on: " + currentNote.getTitle());
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(currentNote.getID());
Log.d("RecyclerAdapter", "Notification Cancelled on: " + currentNote.getTitle());
}
}
}
});
snackbar.show();
}
我的日志......
表A:
03-20 19:05:26.912 32245-32245/owensetiawan.friendlymatch.todolist D/insertNewNote method: Position at: 4
03-20 19:05:26.912 32245-32245/owensetiawan.friendlymatch.todolist D/DBInfo Owen: Insert method called.
03-20 19:05:26.942 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #3 mView = null
03-20 19:05:26.972 32245-32245/owensetiawan.friendlymatch.todolist D/RecyclerView: onCreateVH called!
03-20 19:05:26.972 32245-32245/owensetiawan.friendlymatch.todolist D/RecyclerView: onBindVH called: Deep
03-20 19:05:27.062 32245-32245/owensetiawan.friendlymatch.todolist D/AbsListView: Get MotionRecognitionManager
03-20 19:05:27.062 32245-32245/owensetiawan.friendlymatch.todolist E/MotionRecognitionManager: mSContextService = android.hardware.scontext.ISContextService$Stub$Proxy@c083826
03-20 19:05:27.062 32245-32245/owensetiawan.friendlymatch.todolist E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@3ffac67
03-20 19:05:27.062 32245-32245/owensetiawan.friendlymatch.todolist E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@3ffac67
03-20 19:05:27.102 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{e75147b V.E...... R.....I. 0,0-0,0}
03-20 19:05:27.122 32245-32245/owensetiawan.friendlymatch.todolist E/ViewRootImpl: sendUserActionEvent() mView == null
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.132 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:27.182 32245-32259/owensetiawan.friendlymatch.todolist D/mali_winsys: new_window_surface returns 0x3000, [1592x2395]-format:1
03-20 19:05:27.232 32245-32245/owensetiawan.friendlymatch.todolist W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
03-20 19:05:27.292 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
03-20 19:05:27.292 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: MSG_RESIZED: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.302 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:27.312 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: Current page list:
03-20 19:05:27.312 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #0: page 1393
03-20 19:05:27.312 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #1: page 1394
03-20 19:05:27.312 32245-32245/owensetiawan.friendlymatch.todolist I/ViewPager: #2: page 1395
03-20 19:05:28.042 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processPointer 0
03-20 19:05:28.132 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processPointer 1
03-20 19:05:28.132 32245-32245/owensetiawan.friendlymatch.todolist D/We have liftoff!: DPD Listener called!
03-20 19:05:28.132 32245-32245/owensetiawan.friendlymatch.todolist D/onDateSet method: Date set for: 20/2/2016
03-20 19:05:28.132 32245-32245/owensetiawan.friendlymatch.todolist D/Alarm: Set Alarm method called on: !20/2/2016
03-20 19:05:28.132 32245-32245/owensetiawan.friendlymatch.todolist D/DBInfo: Note retrieved ID of: 5
03-20 19:05:28.242 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #3 mView = null
03-20 19:05:28.262 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #1 mView = android.widget.LinearLayout{d7b9729 V.E...... ......I. 0,0-0,0}
03-20 19:05:28.272 32245-32245/owensetiawan.friendlymatch.todolist E/ViewRootImpl: sendUserActionEvent() mView == null
03-20 19:05:28.312 32245-32259/owensetiawan.friendlymatch.todolist D/mali_winsys: new_window_surface returns 0x3000, [928x176]-format:1
03-20 19:05:28.322 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
03-20 19:05:28.342 32245-32245/owensetiawan.friendlymatch.todolist W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
03-20 19:05:29.172 32245-32245/owensetiawan.friendlymatch.todolist D/AlarmReceiver: Deep called on: 20/3/2016 with ID of: 5
03-20 19:05:29.172 32245-32245/owensetiawan.friendlymatch.todolist D/AlarmReceiver: Receiver called!
03-20 19:05:30.312 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #3 mView = null
03-20 19:05:31.902 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processPointer 0
03-20 19:05:32.312 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processPointer 1
03-20 19:05:32.442 32245-32245/owensetiawan.friendlymatch.todolist D/RecyclerView: deleteItem method called at: 3 on Deep of ID 0
03-20 19:05:35.772 32245-32245/owensetiawan.friendlymatch.todolist D/RV Adapter: Note deleted on: Deep
03-20 19:05:35.792 32245-32245/owensetiawan.friendlymatch.todolist D/DBInfo: deleteNote method called on: Deep
03-20 19:05:35.792 32245-32245/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: Item: Deep of ID: 0 has Alarm Set value of true
03-20 19:05:35.792 32245-32245/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: PendingIntent cancelled of ID: 0
03-20 19:05:35.792 32245-32245/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: Alarm Cancelled on: Deep
03-20 19:05:35.802 32245-32245/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: Notification Cancelled on: Deep
03-20 19:05:39.852 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processKey 0
03-20 19:05:39.952 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processKey 1
03-20 19:05:40.662 32245-32245/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #3 mView = null
附件B :
03-20 21:30:56.382 31168-31168/owensetiawan.friendlymatch.todolist D/DBInfo: Columns created: [_id, note_title, note_content]
03-20 21:30:56.382 31168-31168/owensetiawan.friendlymatch.todolist D/DBHelper Owen: Loading entries: 4 Date: Sun Mar 20 21:30:56 GMT+08:00 2016
03-20 21:30:56.382 31168-31168/owensetiawan.friendlymatch.todolist D/ItemTouchHelper: Callback called!
03-20 21:30:56.382 31168-31168/owensetiawan.friendlymatch.todolist D/Activity: performCreate Call Injection manager
03-20 21:30:56.382 31168-31168/owensetiawan.friendlymatch.todolist I/InjectionManager: dispatchOnViewCreated > Target : owensetiawan.friendlymatch.todolist.MainActivity isFragment :false
03-20 21:30:56.382 31168-31168/owensetiawan.friendlymatch.todolist D/SecWifiDisplayUtil: Metadata value : SecSettings2
03-20 21:30:56.392 31168-31168/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{1489836 I.E...... R.....ID 0,0-0,0}
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onCreateVH called!
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onBindVH called: Factory reset phone
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onCreateVH called!
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onBindVH called: Supermarket
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onCreateVH called!
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onBindVH called: Keepa
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onCreateVH called!
03-20 21:30:56.412 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: onBindVH called: Deep
03-20 21:30:56.432 31168-31183/owensetiawan.friendlymatch.todolist D/mali_winsys: new_window_surface returns 0x3000, [1440x2560]-format:1
03-20 21:30:56.442 31168-31168/owensetiawan.friendlymatch.todolist I/InjectionManager: dispatchCreateOptionsMenu :owensetiawan.friendlymatch.todolist.MainActivity
03-20 21:30:56.442 31168-31168/owensetiawan.friendlymatch.todolist I/InjectionManager: dispatchPrepareOptionsMenu :owensetiawan.friendlymatch.todolist.MainActivity
03-20 21:30:56.442 31168-31168/owensetiawan.friendlymatch.todolist D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
03-20 21:30:56.462 31168-31168/owensetiawan.friendlymatch.todolist W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
03-20 21:30:56.502 31168-31168/owensetiawan.friendlymatch.todolist I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@16d23dc time:60508201
03-20 21:30:56.742 31168-31168/owensetiawan.friendlymatch.todolist D/ViewRootImpl: #3 mView = null
03-20 21:30:57.292 31168-31168/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processPointer 0
03-20 21:30:57.462 31168-31168/owensetiawan.friendlymatch.todolist D/ViewRootImpl: ViewPostImeInputStage processPointer 1
03-20 21:30:57.602 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerView: deleteItem method called at: 3 on Deep of ID 6
03-20 21:31:00.942 31168-31168/owensetiawan.friendlymatch.todolist D/RV Adapter: Note deleted on: Deep
03-20 21:31:00.952 31168-31168/owensetiawan.friendlymatch.todolist D/DBInfo: deleteNote method called on: Deep
03-20 21:31:00.962 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: Item: Deep of ID: 6 has Alarm Set value of true
03-20 21:31:00.962 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: PendingIntent cancelled of ID: 6
03-20 21:31:00.962 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: Alarm Cancelled on: Deep
03-20 21:31:00.962 31168-31168/owensetiawan.friendlymatch.todolist D/RecyclerAdapter: Notification Cancelled on: Deep
请注意Deep如何显示两次,即不删除,以及两个ID为警报集返回 true 这一事实。
我是否会失去理智?我需要重新启动计算机吗? Android漏洞? ?????????????????????????????????????????????????? ???????????? 任何答案都会得到我永恒的感谢。
答案 0 :(得分:0)
如果您只是使用
,您的排名可能会不同步(不确定您目前是如何获得该排名的)getPosition()
然后它与它在屏幕上的位置有关,而不是与集合中的位置有关。
您需要引用RecyclerView使用的布局管理器,然后调用
GridLayoutManager layoutManager = ((GridLayoutManager)mRecyclerView.getLayoutManager());
int position = layoutManager.findFirstVisibleItemPosition() + position;