问题标签 [notifydatasetchanged]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
618 浏览

nullpointerexception - 在 ListFragment 内的适配器上调用 notifyDataSetChanged() 会导致 NullPointerException?

介绍:

我有以下设置:

  1. 一个MainActivitywith 方法onNewIntentand processNewIntent, the MainActivityalso implements FragmentActivity; 并有一个选项卡式片段,它实现FragmentList

  2. listaddactivity创造新事物的活动Parcelable listControlObject

  3. listaddactivity活动发送一个带有包裹的意图,然后在MainActivity'sonNewIntentprocessNewIntent类中重建 listControlObject。

  4. 然而; 我可以接受intent我的onNewIntent方法,它会构建新的listControlObject罚款;但是当我在课堂上调用该adapter.notifyDataSetChanged方法时。FragmentList

日志错误:

onNewIntent方法:

processNewIntent方法:

引发 nullpointerexception 的特定行:

ListFragment班级:

0 投票
1 回答
997 浏览

android - notifyDataSetChanged() 不刷新列表视图

这是我的适配器:

这是我的片段,它有一个在调用 Conversa.addMessage() 时不会刷新的列表视图。

如果我收到一条聊天消息,它不会出现在列表中,尽管该消息在日志中。当我触摸 edittext 来编写消息时,它会刷新视图并显示消息。我希望它一出现就出现。请帮我。

0 投票
1 回答
248 浏览

android - The content of the adapter has changed but ListView did not receive a notification. (feeding list out main thread)

Im developing a chat app and my adapters (BaseAdapter), that holds the chat logs, are in Service, cause the variable that give me IRC resources are in Service. When an activity is binded, my chat fragments gets the adapters from the service. At first, i was trying to notifyDataSetChanged() from adapter itself, then i discover that i need to call it from main UI thread. So i send a broadcast to fragment to notify the adapter inside, the fragment uses the main UI thread. Now, im getting this problem cause im feeding the list outside the UI thread (from Service) and notifying it on main thread. But it need this adapter on Service. What should i do?

This is my adapter. There are one of it for each conversation. This adapter remains in Service:

}

This is my ChatFragment:

}

This is only my receive message methods and adapter variables on service:

The same thing happens on my message log list and to my user list (nick list). The userlist adapter is on service too, and i have a listfragment to show it; In both cases i'm updating the arraylists from service, and notifying them adapters by sendBroadcast() and receiving on fragment that holds the adapter;

0 投票
1 回答
29 浏览

java - 当用户响应活动时,我的列表视图没有更新?

我有一个包含许多片段的主要活动,其中一个包含一个列表视图,带有适配器homeworkListAdapter,这个适配器确实显示任何以homeworkItems. 我的活动打开了另一个活动(HomeworkAddActivity,它从用户那里获取一个字符串并将其放入一个数组homeworkItems中,这一切都有效,因为我已经独立检查了每个步骤。但是,当我尝试使用这个新项目(使用.notifyDataSetChanged)更新列表视图时没有更新,我已经尝试修复此问题 3-4 小时,请帮助。

代码

MainActivity

HomeworkAddActivity

0 投票
4 回答
2779 浏览

android - Android,单击列表项后刷新列表视图

我有一个小问题,单击列表项后,项目上的复选框不会改变状态。更新工作完美,可能是 setChecked,但退出并重新运行活动后会出现更改。我读了很多关于notifyDataSetChange(),它可能有效,但不是。我该如何修复它,就像单击项目 chechbox 值后会改变。

0 投票
0 回答
381 浏览

android - 调用 notifyDataSetChanged 后 Android setOnClickListener 无法正常工作

我确实有一个从数据库更新的 ArrayAdapter。当数据更新notifyDataSetChanged();时被调用并更新数据列表。我的问题是 onListItemClick 没有更新。当用户单击第一个列表项时,会检查每个 1-9-18.. 并更改背景颜色。

应该这样做是因为“ListView 会回收其行,因此您需要确保在适配器的 getView() 方法中重置视图的状态。” 关联

这是怎么做到的?

onListItemClick

0 投票
1 回答
533 浏览

java - 用户单击项目android后更新listview

我有一个 arraylist 存储数据库中的数据并将其显示在列表视图中,当用户单击一个项目时,数据库中的数据会更新,我想知道如何刷新列表视图中的项目以显示更新的数据。

这是我的 setOnItemClickListener 代码

如何使用notifyDataSetChanged刷新列表视图?

0 投票
1 回答
679 浏览

android - 用于带有文本消息和文件的聊天应用程序的 Android 列表视图

我正在android中开发聊天应用程序。我正在使用 listview 来显示短信。现在我要在聊天应用程序中实现文件传输。文件传输的工作原理是,当设备A传输任何文件时,将文件上传到服务器,并将相应的下载url以短信的形式发送到设备B。设备 B聊天列表视图中,我将显示下载该文件的按钮。当用户单击 listview 中的特定按钮时,我想使用异步任务下载文件,同时我想在 listview 中显示进度条。如果设备 B收到任何其他文本消息,则在下载文件时,我必须使用 notifyDatasetChanged 刷新列表视图以显示新消息。

如何保持进度条不受notifyDatasetChanged的影响?

还有其他好的解决方案可以在聊天列表视图中显示下载 url 并下载文件并将其显示给用户吗?

0 投票
1 回答
562 浏览

android - Android CustomListAdapter notifydatachange() 不工作

我想使用 Custom ArrayAdapter显示项目列表。

我将通过单击按钮插入数据。

MainFragment.java

我的布局文件如下。

主要的.xml

MyFragment.java

MyFragment.java 的布局文件是

更新.xml

我的数据库类是

数据库类.java

onclick 按钮,数据被插入到数据库中。但它没有反映在 UI 中。为什么我的列表视图没有更新?

谢谢

0 投票
2 回答
449 浏览

android - 无法实现 notifyDataSetChanged()

我正在使用 aFragmentStatePagerAdapter为了达到一个VerticalPageAdapter目的,我必须创建一个动态编号的相同 Fragment 关于哪个Button被按下,所以,我只检索getItem()方法中的指定片段:

getCount()返回一个关于Button在其他片段中按下的动态数字:

但这给了我IlligalStateException,因为我没有被调用notifyDataSetChanged(),所以,我将通知添加到我用来提高片段数量的方法中:

但我也得到了IlligalStateException

因此,我决定在返回 Value 之前将其添加到 getCount() 方法中,如下所示:

但这给了我一个StackOverflowError