ListView(LV)を更新する際に問題が発生し、アイテムを削除しようとするたびに、次のエラーメッセージが表示されます:The content of the adapter has changed but ListView did not receive a notification
。別のビューからアンドロイドのListViewに通知するには?
しかし、私はここにLVにnotify()
を呼び出す行うには、私のコードです:
public void deleteNotif(Reminder reminder)
{
NotificationDBHelper db = new NotificationDBHelper(getBaseContext());
this.mNotificationsHours.remove(reminder); // here I remove the element from the db
db.delete(reminder); // here I remove the element from the list
synchronized (this.mNotificationListLV)
{
Log.d("sync called","hi stackoverflow");
this.mNotificationListLV.notify();
}
}
そして、私はsynchronized()
を使用しないときは、エラープロンプト:object not locked by thread before notify()
を。私は何をすべきか分からない。
私はLV内の項目のいずれかからOnClickEventListener()
からdeleteNotify(Reminder reminder)
を呼び出す:
public NotificationButton(Context context, AttributeSet attrs) {
super(context, attrs);
//getAttr(context, attrs);
this.mImg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
NotificationConfig nc = NotificationConfig.getInstance();
nc.deleteNotif(mReminder);
}
});
super.setImg(R.drawable.ic_delete_forever_black_24dp,0xc40003);
}
感謝。お使いのアダプタ参照の上notifyDataSetChanged
を適用します。あなたはnotify
関数がすべて
ソリューションでは、ここで必要とされていないwait-notify
ロック機構のための基本的Object
クラスから来ている
ではなく、アダプタのlistView
に通知申請している
notifyDataStateChange()メソッド –
を使用してください。スタックオーバーフローを歓迎します。あなたの周りを知るために[ウェルカムツアー](https://stackoverflow.com/tour)に行ってください。ここで(そしてあなたの最初のバッジを得るために)、[最小限で完全で証明可能な例](https://stackoverflow.com/help/mcve)の作成方法と[良い質問をする方法](https ://stackoverflow.com/help/how-to-ask)ので、フィードバックや役に立つ回答を得る機会が増えます。 – DarkCygnus