notifyDataSetChanged不起作用适配器 [英] adapters notifyDataSetChanged does not work

查看:347
本文介绍了notifyDataSetChanged不起作用适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑2:

我没有解决我的问题,但我不知道如何:S I在动我的code片段有点绕,一个突然它的工作。一定是做了错误的顺序的东西,但它的怪异,检查了很多次。感谢您的帮助和抱歉,我不能发布一个答案;)

喜。

我有我试图刷新更新自我,当我一个元素添加到列表视图
底层的数组列表。

下面是code片断:

 私人无效的addEvent(){
    arrlEvents.add(事件);
    adptEvents.notifyDataSetChanged();
    updateSaveFile();
    filterList();
}

该arrlEvents与事件的基本ArrayList和IM添加一个事件,试图更新notifyDataSetChanged()列表视图,但它不工作。谁能帮助?

感谢您的时间:)

编辑:
这里是源$ C ​​$ C适配器:

 私人ArrayAdapter<事件> adptEvents;
adptEvents =新ArrayAdapter<事件>(EventCalendar.this,R.layout.list_items,arrlEvents);


解决方案

我已经看到,有时它只是随机犯规通知适配器。

尝试使用adptEvents为受保护或公开在全球范围内。

我发现,当这并不工作。您只需重新重新设置适配器,刚刚替补为notifyDataSetChanged():

  adptEvents =新ArrayAdapter<事件>(EventCalendar.this,R.layout.list_items,arrlEvents);

编辑:

继承人从一个应用程序code剪断我写的作品。

类定义:

 公共className类扩展ListActivity实现AdapterView.OnItemSelectedListener {

全局变量:

  CustomAdapter适配器;

在OnCreate()中:

 适配器=新CustomAdapter(这一点,R.layout.layout_name,数据集);
setListAdapter(适配器);

每当我需要通知

  adapter.notifyDataSetChanged();

EDIT 2:

I did solve my problem, but i don't know how:S I was moving my code snippets a bit around, a suddenly it worked. Must have done something in the wrong order, but its weird, checked it many times. Thanks for you help, and sorry I can't post an answer ;)

Hi.

I have a list view which I'm trying to refresh to update it self when i add an element to the underlying array list.

Here is the code snippet:

private void addEvent() {
    arrlEvents.add( event );
    adptEvents.notifyDataSetChanged();
    updateSaveFile();
    filterList();
}

The arrlEvents is the underlying arraylist with the events, and im adding one event, trying to update the list view with notifyDataSetChanged(), but it doesnt work. Can anyone help?

Thanks for your time:)

EDIT: Here is the source code for the adapter:

private ArrayAdapter<Event> adptEvents;
adptEvents = new ArrayAdapter<Event>( EventCalendar.this, R.layout.list_items, arrlEvents );

解决方案

I have seen that sometimes it just randomly doesnt notify the adapter.

Try using adptEvents as protected or public on a global scope.

I have found that when that doesnt work. You can just re set the adapter again, just substitute the notifyDataSetChanged() for:

adptEvents = new ArrayAdapter<Event>( EventCalendar.this, R.layout.list_items, arrlEvents );

Edit:

Heres a code snipper from an App I wrote that works.

Class definition:

public class ClassName extends ListActivity implements AdapterView.OnItemSelectedListener {

Global Variable:

CustomAdapter adapter;

in OnCreate():

adapter = new CustomAdapter(this,R.layout.layout_name,dataSet);
setListAdapter(adapter);

Whenever I need to notify

adapter.notifyDataSetChanged();

这篇关于notifyDataSetChanged不起作用适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆