use*_*702 5 android android-listview android-adapter
我ListFragment的数据由自定义适配器(SimpleAdapter在我的情况下)填充.我notifyDataSetChanged()在课堂上使用扩展时遇到了问题ListFragment.经过大量的浏览和之后的几个(有用的)Stack Overflow帖子:
listview没有使用notifydatasetchanged()调用进行更新
在notifyDataSetChanged之后Android ListView没有刷新
从BaseAdapter调用notifyDataSetChanged时,ListView不会更新
我知道松散(并且非常不推荐)的解决方法是使用重新设置适配器setListAdapter().但是我现在也面临着这个问题.
文档http://developer.android.com/reference/android/app/ListFragment.html#setListAdapter(android.widget.ListAdapter)提到了setListAdapter()
提供列表视图的光标.
但我还是有一些问题.
Q1.使用setListAdapter()"指向"同一适配器实例多次初始化适配器?
Q2.当使用setListAdapter()多次设置适配器时,调用getListAdapter()然后调用notifyDataSetChanged()时会发生什么?
Q3.这个问题基于Q2的假设 - 当notifyDataSetChanged()多次设置适配器时调用,哪些适配器实例(这部分是假设),如果它们存在'实际上是通知变更?
我是Android的初学者,我相信有一些我不理解的细微差别.如果你能澄清这些问题,我将非常感激.也非常感谢你的时间.
Q1. 使用 setListAdapter() 多次初始化适配器是否“指向”同一个适配器实例?
Ans:初始化适配器将仅指向您使用设置的最后一个实例setListAdapter。
Q2. What actually happens when a call is made to getListAdapter() and then to
notifyDataSetChanged() when an adapter has been set multiple times using
setListAdapter() ?
Run Code Online (Sandbox Code Playgroud)
Ans:无论您初始化了多少个适配器,都只会使用 检索最后一个实例getListAdapter()。当您notifyDataSetChanged()仅使用检索到的最后一个实例时getListAdapter(),将刷新即;最后一个实例将被重新加载(通过调用getView)。
Q3. This question is based on an assumption from Q2- when notifyDataSetChanged() is
called when an adapter is set multiple times, which of those adapter instances (this
part is the assumption), if they exist' is actually being notified for change ?
Run Code Online (Sandbox Code Playgroud)
Ans:上面的答案包含了对此的解释。
| 归档时间: |
|
| 查看次数: |
618 次 |
| 最近记录: |