Listview不显示的问题学习

一 .ListView 不执行getView()方法  

setAdapter 时,首先会执行getCount(),当getCount()  返回的是0时,就不会去执行getView()方法, 如果 开启线程去下载数据,然后在getCount()中返回其size, 开始的时候因为还没有下载数据,返回的size可能是0,所以不会去调用getView()方法,界面就不会被填充。    下载完成后  通过notifyDataSetChanged()方法 重新加载适配器,就会调用getView()方法了.

 

二. 重点参考 stackoverflow中的

http://stackoverflow.com/questions/7391797/listview-not-getting-populated-getview-isnt-getting-called

http://stackoverflow.com/questions/10165263/listview-is-not-populating-yet-getview-is-called?rq=1

 

 

Sometimes it seems notifyDataSetChanged() won’t work for you. Reasons why,

Your adapter loses reference to your list. When you first initialize the Adapter it takes a reference of your arrayList and pass to its superclass. But if you reinitialize your existing arrayList it losts the reference hence the communication channel with Adapter :(.

Always creating and adding a new list to the Adapter. Do like this:

  1. Initialize the arrayList while declaring globally.
  2. Add List to the adapter directly with out checking null and empty condition. Set the adapter to the list directly(don’t check for any condition). Adapter gives you the guarantee that wherever you are changes the data of arrayList it will take care, but never loose the reference.
  3. Add data to the arrayList Every time(if your data is completely new than you can call adapter.clear() and arrayList.clear() before actually adding data to the list) but don’t set the adapter i.e If the new data is populated in the arrayList than just adapter.notifyDataSetChanged()

 三. notidydatasetchanged

 

http://stackoverflow.com/questions/3669325/notifydatasetchanged-example

 

四。最后原因是ScrollView中的ListView

http://blog.csdn.net/aiqing0119/article/details/8446785

转载于:https://www.cnblogs.com/chuiyuan/p/4205670.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值