adapter

Android开发-- The content of the adapter has changed but ListView did not receive a notification - With AsyncTask

北战南征 提交于 2020-03-30 03:20:52
最近在联系开发DaysMatter时遇到一个问题: app中使用ListView来展示所有事件,每次添加完事件后使用下面代码来更新ListView. 1 toDoListView.refreshDrawableState(); 会出现如下错误,错误内容是讲ListView的adapter必须是在UI线程中修改,不能在后台线程中修改 java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131034172, class android.widget.ListView) with Adapter(class android.widget.SimpleAdapter)] 在SO上看到一个类似的问题(http://stackoverflow.com/questions/9771017/the-content-of-the-adapter-has-changed-but

Android The content of the adapter has changed but ListView did not receive a notification

老子叫甜甜 提交于 2020-03-30 03:08:29
The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread 原因:没有在主线程里通知。。。。 1、bug 出现的地方 listView.class 1487行 if (mItemCount == 0) { resetList(); invokeOnItemScrollListener(); return; } else if ( mItemCount != mAdapter.getCount( )) { throw new IllegalStateException("The content of the adapter has changed but " + "ListView did not receive a notification. Make sure the content of " + "your adapter is not modified from a background thread, but only " + "from the UI

The content of the adapter has changed but ListView did not receive a notification

◇◆丶佛笑我妖孽 提交于 2020-03-30 03:08:10
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131231086, class android.widget.ListView) with Adapter(class com.tongyan.guangzhou.subway.inspect.act.table.TaskCheckMainAct$FacilityTaskCheckAdapter)] at android.widget.ListView.layoutChildren(ListView.java:1576) at android.widget.AbsListView.onTouchUp(AbsListView.java:3911) at

The content of the adapter has changed but ListView did not receive a notification

浪子不回头ぞ 提交于 2020-03-30 03:07:57
  问题原因:Adapter数据更新后,没有及时使用notifyDataSetChanged()方法通知UI,导致出现数据不一致而报错。 java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131690143, class android.widget.ListView) with Adapter(class com.hotalk.ui.homepage.favorites.FavoritesListAdapter)] at android.widget.ListView.layoutChildren(ListView.java:1510) at android.widget.AbsListView.onLayout(AbsListView.java:1260) at android.view.View.layout(View.java:7204) at

Adapter.notifyDataSetChanged()源码分析以及与ListView.setAdapter的区别

痴心易碎 提交于 2020-03-30 03:04:06
一直很好奇,notifyDataSetChanged究竟是重绘了整个ListView还是只重绘了被修改的那些Item,它与重新设置适配器即调用setAdapter的区别在哪里?所以特地追踪了一下源码,过程如下: 一、notifyDataSetChanged实现机制 自定义Activity中有如下调用语句: checkoutAdapter.notifyDataSetChanged(); 点击notifyDataSetChanged()进行代码跟踪。首先,进入到BaseAdapter的notifyDataSetChanged方法: public void notifyDataSetChanged() { mDataSetObservable.notifyChanged(); } 我们发现其实就是DataSetObservable这个对象在发生作用,点击notifyChanged进行追踪。 public class DataSetObservable extends Observable<DataSetObserver> { /** * Invokes onChanged on each observer. Called when the data set being observed has * changed, and which when read contains the new

How to use adapter to prevent Faraday from changing capitalize headers

二次信任 提交于 2020-03-25 17:54:09
问题 I'm using Faraday to create an SDK that will interact with an API, and I need to send two headers API_SIGNATURE and API_REQUEST_TIME, so that's what I've created: class APIClient def initialize(api_key) @api_key = api_key end def get_users request.post('/users') end private def request Faraday.new(@@BASE_API_URL, headers: headers) end def headers timestamp = Time.now.to_i.to_s return { 'API_SIGNATURE': Digest::MD5.hexdigest(@api_key + timestamp), 'API_REQUEST_TIME': timestamp } end end And

为RecyclerView打造通用Adapter

风流意气都作罢 提交于 2020-03-21 16:57:17
##RecycleView简单介绍 RecyclerView控件和ListView的原理有非常多相似的地方,都是维护少量的View来进行显示大量的数据。只是RecyclerView控件比ListView更加高级而且更加灵活。当我们的数据由于用户事件或者网络事件发生改变的时候也能非常好的进行显示。和ListView不同的是,RecyclerView不用在负责Item显示相关的功能。全部有关布局、绘制、数据绑定等都被分拆成不同的类进行管理。同一时候RecyclerView控件提供了下面两种方法来进行简化和处理大数量集合: 1.基本使用 RecycleView的基本使用 RecycleView导包(可有可无) dependencies中加入 compile'com.android.support:recyclerview-v7:23.1.1' 在布局文件里定义 <android.support.v7.widget.RecyclerView android:id="@+id/rcv_history" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.RecyclerView> 3.对其进行初始化 rcv_history =

Adapter

…衆ロ難τιáo~ 提交于 2020-03-20 07:02:04
今天是第一次在Mac book上编程,与在windows上写代码相比,既新鲜又充斥在许多小问题,还好很快掌握了 Adapter: 适配器Adapter是一种结构设计模式,其主要作用是允许不兼容的对象间通过一个转换接口协同工作。 适配器本身扮演的角色是两个对象间的包装器,通过对不兼容的对象进行包装从而生成目标对象的统一接口。 其实现就是适配器从目标对象继承,然后聚合不兼容的对象 #include <iostream> #include <string> class Target { public: virtual ~Target() = default; virtual std::string Request() const { return "Target: The default target's behavior."; } }; class Adaptee { public: std::string SpecificRequest() const{ return ".eetpadA eht fo rovivaheb laicepS"; } }; class Adapter : public Target { private: Adaptee *m_pAdaptee; public: Adapter(Adaptee* pAdaptee):m_pAdaptee(pAdaptee){

Adapter的getView方法详解

爱⌒轻易说出口 提交于 2020-03-20 03:05:41
来自: http://blog.csdn.net/yelbosh/article/details/7831812 BaseAdapter就Android应用程序中经常用到的基础数据适配器,它的主要用途是将一组数据传到像ListView、Spinner、Gallery及GridView等UI显示组件,它是继承自接口类Adapter,我们经常使用的ListView 的adapter,即SimpleAdapter,是继承自BaseAdapter的,BaseAdapter是一个基类,没有实现绑定数据的功能,SimpleAdapter实现了基本控件的绑定,如TextView,Button,ImageView).已经为我们实现好了数据优化工作,这些适配器使用相同组件动态绑定数据的方式进行优化。为什么需要优化呢?因为如果我们有上亿个项目要显示怎么办?为每个项目创建一个新视图?这不可能,因为内存有限制。实际上Android为你缓存了视图。Android中有个叫做Recycler的构件,下图是他的工作原理: 如果你有10亿个项目(item),其中只有可见的项目存在内存中,其他的在Recycler中。其实我的理解Recyler就是一个队列,用来存储不在屏幕范围内的item,如果item滚出屏幕范围,那么就入队,这里的滚出是完全滚出,即边界等也要完全滚出。如果新的item要滚进来

小例子背后的大道理——Adapter模式详解

允我心安 提交于 2020-03-20 02:21:01
上回问题回顾 前文 说到一位用户拿着业界标准开关(一个标准的StandardSwitcher,它依赖IStandardSwitchable接口才能工作,然而目前我们的灯并不支持这个接口)出现在我面前,叫嚣着他的“标准开关”应该能打开我们的灯。好吧,这个需求是合理的,的确应该支持。但是该死的是,为什么没有早一点儿知道这个标准的存在呢?这样就不需要花费时间和人力定义这个接口,现在也不会这么纠结。和上次一样,先讲故事、演进方案,再分析背后的思想。 这回主要讲解Adapter模式,GoF讲解了这个模式是什么,怎么用,用在什么地方。我想来解释一下Adapter模式的要点是什么,对Adapter模式的延展,以及对Adapter模式的误用。顺便得瑟一下我对面向对象设计的理解。 两个方案 现在有两个选择。 让我们的灯直接支持标准开关。也就是让灯实现IStandardSwitchable接口。 好处:成本低,实现方式优雅。 坏处:相当于放弃了已经买了我们的灯,又想用标准开关的用户。 不改变现在的灯,让标准开关能打开我们的灯。标准接口我们改不了,灯也不能改。好在计算机界有句话,叫“加一层可以解决一切问题”。这让我想到了买外国电器附赠的那个电源接口转换器。现在,我们的灯需要个类似的玩意儿。 好处:支持所有的灯。 坏处:这东西都是要附赠的,会降低我们的利润。 第一个方案很简单