如何清空androidc listview 清空控件的内容

Android中的ListView内容刷新问题
- 将安卓进行到底... - ITeye技术网站
博客分类:
最近在学习Android的listView控件时遇到了一个问题,如何添加一个Item到ListView中并及时的刷新出来。在网上查了很多帖子,很多人在问,也很多人在解答,但是总的来说都没找到详细的解决方案。对于ListView与数据库的同步,高手们建议使用ContentProvider对象。但是如果我不使用数据库呢?也有人回答用notifyDataSetChanged()方法。这倒是一个正确的解决方案,但是对于新手来说,还是比较困惑怎么去用,这里我贴一下我的用法:
OnClickListener listener2 = new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Map&String, Object& m = new HashMap&String, Object&();
String tiString
= tv.getText().toString(); // 注意这里我为什么要取出这个EditText的内容
m.put("prod_na", tiString); // 而不这样写 m.put("prod_na", tv.getText());
m.put("prod_type", tiString); // 因为tv.getText()返回的是Editable对象,真正的数据是被缓存的,
// 也就是说你后续的EditText改动都会影响之前添加的Item
coll.add(m);
// 取回Adapter对象,用于调用notifyDataSetChanged方法。
SimpleAdapter sAdapter = (SimpleAdapter)lv.getAdapter();
sAdapter.notifyDataSetChanged();
这里涉及到了Android中的MVC模式概念,如何存储数据,控制和显示。
你可以认为ListView是一个View,那么mode是什么呢?显然是SimpleAdapter对象,而Control又是什么呢?那只能是notifyDataSetChanged()了。当数据变化时,也就是SimpleAdapter所处理的数据变化了,那么我们就需要调用 notifyDataSetChanged 去通知View作出改变。
浏览 16866
marine8888
浏览: 335329 次
来自: 深圳
今天刚好需要这个效果,非常感谢!
不错!学习了!
lan恰 写道怎么感觉这个跟android没半毛钱关系的呢?C ...
学习了,但怎么设置单向边框呢?比如下边框,上边框!二次元同好交流新大陆
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(2710)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'android ListView的item与其子控件的焦点问题',
blogAbstract:'ListView默认情况&\r\n当item有焦点时,item上的button等子控件获取不到焦点;\r\n当子控件有焦点时,item无焦点无法响应onItemClick事件\r\n\r\nViewGroup.FOCUS_AFTER_DESCENDANTS:表示item的子控件优先于item获得焦点;\r\nViewGroup.FOCUS_BEFORE_DESCENDANTS:表示item优先于其子控件获得焦点。\r\n\r\n解决办法:\r\n',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:0,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}简化Android ListView使用的控件:SuperListview
-------------
新增文件夹...
新增文件夹
(多个标签用逗号分隔)
这个库让Android ListView使用方式更加简便。无需将 ListView 嵌入到 FrameLayout或空视图中的方式来增加进度条,该控件已经帮你搞定一切。
list.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener {
public void onRefresh() {
// Do your refresh
// when there is only 10 items to see in the list, this is triggered
list.setupMoreListener(new OnMoreListener() {
public void onMoreAsked(int numberOfItems, int numberBeforeMore, int currentItemPos) {
// Fetch more from Api or DB
// the 2nd parameters is true if you want SuperListView to automatically
// delete the item from the listview or false if you don't
list.setupSwipeToDismiss(new SwipeDismissListViewTouchListener.DismissCallbacks() {
public boolean canDismiss(int position) {
return true
public void onDismiss(ListView listView, int[] reverseSortedPositions) {
// Do your stuff like call an Api or update your db
}}, true);
ProgressBar while adapter hasn't been set
EmptyView if adapter is empty
SwipeRefreshLayout (Google's one)
Infinite scrolling, when you reach the X last item, load more of them.
Swipe To Dismiss for the SuperListView (doesn't make sense for a gridview) (Thanks )
GridView with SuperGridView
Open to suggestions (and Pull Request ofc) for others :)
项目主页:
相关资讯  — 
相关文档  — 
发布时间1: 09:22:13
同类热门经验
93597次浏览
180505次浏览
76023次浏览
107670次浏览
70440次浏览
OPEN-OPEN, all rights reserved.}

我要回帖

更多关于 listview 清空item 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信