展示新项目,在ListView的顶部 [英] Display new items at the top of a ListView

查看:146
本文介绍了展示新项目,在ListView的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个列表来填充一个ListView()。用户能够将项目添加到列表中。不过,我需要的项目,在ListView控件的顶部显示。以相反的顺序显示它如何插入一个项目,在我的名单的开始?

I'm using a list to populate a ListView (). The user is able to add items to the list. However, I need the items to be displayed at the top of the ListView. How do I insert an item at the beginning of my list in order to display it in reverse order?

推荐答案

您应该使用的<一个href="http://developer.android.com/reference/android/widget/ArrayAdapter.html"><$c$c>ArrayAdapter和使用<一href="http://developer.android.com/reference/android/widget/ArrayAdapter.html#insert%28T,%20int%29"><$c$c>insert(T, INT) 的方法。

You should probably use an ArrayAdapter and use the insert(T, int) method.

例如:

ListView lv = new ListView(context);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.id...);
lv.setAdapter(adapter);
...
adapter.insert("Hello", 0);

这篇关于展示新项目,在ListView的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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