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

查看:18
本文介绍了在 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?

推荐答案

你可能应该使用 ArrayAdapter 并使用 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天全站免登陆