notifyc datasettInvalidated和notifyc datasettChanged有什么区别

如何Simpleadapter写在线程中_百度知道
如何Simpleadapter写在线程中
List&HashMap&&String,String&, int,哪位大神知道是什么原因我把一个Simpleadapter写在线程中代码报错?错误如下:The constructor SimpleAdapter(new Runnable(){}, String[]
notifyChanged().*&#47.notifyInvalidated()你随便放的什么数据,然后再通知adapter相对应的组件更新就可以啦;public void notifyDataSetChanged() {mDataSetO调这两个方法.notifyDataSetInvalidated();simpleAsimpleAdapter.notifyDataSetChanged(),把数据放进去后SimpleAdapter simpleAdapter,源码在下边;}public void notifyDataSetInvalidated() {mDataSetO*** Notifies the attached View that the underlying data has been changed* and it should refresh itself。&#47
其他类似问题
线程的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁2148人阅读
FragmentActivity中 进行重新加载item对象不起作用 重新初始化Adapter对象不行 notifyDataSetChanged 也不行 在定义的 Adapter对象中添加一个方法&
setFragmentsList 就可以解决了以下是代码实现
1.自定义Adapter
public class FragmentsPagerAdapter extends FragmentPagerAdapter {
private List&Fragment& mF
public FragmentsPagerAdapter(FragmentManager fm, List&Fragment& fragments) {
super(fm);
this.mFragments =
public void setFragmentsList(FragmentManager fm, List&Fragment& fragments){
if (this.mFragments != null) {
FragmentTransaction ft = fm.beginTransaction();
for (Fragment f : this.mFragments) {
ft.remove(f);
ft.commit();
fm.executePendingTransactions();
this.mFragments =
notifyDataSetChanged();
public Fragment getItem(int position) {
return mFragments.get(position);
public int getCount() {
return mFragments.size();
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
public static class DummySectionFragment extends Fragment {
public DummySectionFragment() {
public static final String ARG_SECTION_NUMBER = &section_number&;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
TextView textView = new TextView(getActivity());
textView.setGravity(Gravity.CENTER);
Bundle args = getArguments();
textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER)));
return textV
2.设置Adapter :Handler中进行重新设置的Adapter
private Handler mHandler = new Handler(){
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
mPageViews = new ArrayList&Fragment&();
PlayerFragment playerView =
PlayerData player =
for (int i = 0; i & mListPlayer.size(); i++) {
player = mListPlayer.get(i);
playerView = new PlayerFragment(context, player);
mPageViews.add(playerView);
if(mAdapter == null){
mAdapter = new FragmentsPagerAdapter(getSupportFragmentManager(), mPageViews);
} else{ // 设置
mAdapter.setFragmentsList(getSupportFragmentManager(), mPageViews);
mViewPager.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
mAdapter.notifyDataSetChanged();
Toast.makeText(context, R.string.no_data, Toast.LENGTH_LONG).show();
mPageViews = new ArrayList&Fragment&();
InstructorFragment instructorView =
Instructor instructor =
for (int i = 0; i & mListInstructor.size(); i++) {
instructor = mListInstructor.get(i);
instructorView = new InstructorFragment(context, instructor);
mPageViews.add(instructorView);
if(mAdapter == null){
mAdapter = new FragmentsPagerAdapter(getSupportFragmentManager(), mPageViews);
mAdapter.setFragmentsList(getSupportFragmentManager(), mPageViews);
mViewPager.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:67579次
排名:千里之外
原创:22篇
评论:38条
(1)(3)(2)(1)(2)(1)(2)(4)(6)Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
What does the method adapter.notifyDataSetInvalidated() accomplish?
There is no documentation on it.
I am trying to reload a ListView and notifyDataSetChanged or notifyDataSetInvalidated don't seem to accomplish anything.
4,235155183
It depends on the adapter implementation... if you take a look of the source code you will see that:
notifyDataSetInvalidated() calls the notifyInvalidated() of the DataSetObservable class ()
Then, notifyInvalidated() calls the onInvalidated() method for each DataSetObserver ().
Then comes the funny part: onInvalidated() ...
This is its implementation:
public void onInvalidated() {
// Do nothing
DataSetObserver is an abstract class, so it's up to the subclass to decide what to do on onInvalidated().
102k31247214
As far as I know, the notifyDataSetInvalidated() method stops the adapter from accessing the data (in case it's invalid, unavailable, etc.). The notifyDataSetChanged() method updates the ListView so you can see the new data added, but you have to call it in the UI thread.
It helped me a lot to watch
-- there are two sections where they mention those methods and explain how to use them correctly. Maybe it helps you too :)
36.8k674112
I recently ran into this question and wanted to elaborate for those who are wondering programmatically what is happening when you call notifyDataSetChanged() and notifyDataSetInvalidated(). *Short answer, go
As @Cristian stated in his answer, when you call these notify methods on your Adapter it basically calls through a few classes and ends up calling onChanged()/onInvalidated() on the registered DataSetObservers for your Adapter.
If you follow the code you will indeed see that
is abstract as stated, and that the onChanged()/onInvalidated() methods are empty waiting for implementation by a subclass.
If this were the end of the story, then why do Android framework engineers keep telling us to call these methods if they do nothing? It took some digging but it turns out there is already a subclass of this DataSetObserver called
and it lives in the abstract class
(which is extended by classes like GridView and ListView). This observer is automatically created by Android when you
on your AdapterView and gets
to your Adapter.
It is here that you can see all the crazy stuff these methods actually do do. The documentation is poor and at first I thought I needed to register my own subclassed DataSetObserver to get these functioning, but turns out one is already created for you.
*Something I thought might be useful: I believe that you can register more than one DataSetObserver to your Adapter (in addition to the default one). This would allow you to do some extra work if needed (like maybe swap a progress bar view with an image view when bitmaps are done downloading).
According to the "" lecture, you should use it each time the listView has nothing to show (meaning empty data).
One example they talk about is when the filtering is done (on "publishResults" method). on the lecture video, it's on 36:00 .
The weird thing is, why didn't they just merge it with notifyDataSetChanged, which could check for the number of the items and decide to call it by itself...
According to what I've seen, what was talked on the lecture isn't quite right. if the adapter has shown some content before, and now it doesn't contain anything, and now you call notifyDataSetInvalidated, nothing will happen, so the content will remain, so I think it's safe to use notifyDataSetInvalidated only when the data doesn't change.
For example, if you handle the filtering, and you get the same results (and maybe it's enough to check the number of results) as before, you can call notifyDataSetInvalidated instead of notifyDataSetChanged
25.3k25138272
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledandroid notifydatasetchanged 没有作用_百度知道
android notifydatasetchanged 没有作用
我在做一个即时通讯软件,自己发送出去的时候调用 notifydatasetchanged有显示。从messagemanager那边接回来的消息加到数据里边之后调用 notifydatasetchanged没有作用,必须滑动一下listView才能显示出来
项目中使用ViewPager+Fragment实现tab分页+子tab页内容滑动效果.0之后提出fragment概念正逐渐取代tabhost的地位。
点击个个tab1更换pageadapter的值实现数据的更新。通过继承fragmentpageadpater你会发现使用起来很方便android3
提问者评价
其他类似问题
按默认排序
其他1条回答
谁掉的 是listview还是 adapter??
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁如何使用 notifyDataSetChanged?
我想使用 Data.java 方法来保存数据。它包含数据:
private ArrayList&String& data = new ArrayList&String&();
public int getsize() {
return this.data.size();
public String getdata(int i) {
return this.data.get(i);
public void adddata(String s) {
return this.data.add(s);
onCreate 中的 AActivity类:
Data d = (Data)this.getApplication();
String test = new String[d.getsize()];
for(i = 0; i & d.getsize(); i++) {
test[i] = d.getdata(i);
//to show in list
DataAdapter = new DataAdapter (this, test);
setListAdapter(DataAdapter);
当点击按钮时,开始运行BActivity类。在BActivity类中,代码如下:
Data d = (Data)this.getApplication();
d.adddata("newdata");
onResume() 中的 AActivity类:
public void onResume(){
super.onResume();
this.DataAdapter.notifyDataSetChanged();
但是 list为什么不更新?我确定数据已经保存了。
DataAdapter:
public DataAdapter(Context ctxt, String[] d) {
this.data = new String[d.length];
myInflater = LayoutInflater.from(ctxt);
for(i = 0; i & d. i++) {
data[i] = d[i];
public View getView(int position, View convertView, ViewGroup parent) {
ViewTag viewT
if(convertView == null) {
convertView = myInflater.inflate(R.layout.row_bookmark_list, null);
viewTag = new ViewTag((TextView)convertView.findViewById(R.id.tv));
convertView.setTag(viewTag);
viewTag = (ViewTag) convertView.getTag();
viewTag.tv.setText(data[position]);
class ViewTag {
public ViewTag(TextView t) {
按赞数排序
你这个数据可以放在Application里
其他相似问题
相关参考资料

我要回帖

更多关于 dataset用法 的文章

 

随机推荐