Java 将项添加到ListView的中间

Java 将项添加到ListView的中间,java,android,android-listview,Java,Android,Android Listview,现在,我正在使用以下代码向listView添加一个项目: SimpleAdapter adapter; List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>(); ListView listthings; int[] to; String[] from; private void addItem() { HashMap<Str

现在,我正在使用以下代码向listView添加一个项目:

SimpleAdapter adapter;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
ListView listthings;
int[] to;
String[] from;

private void addItem() {
    HashMap<String, String> map = new HashMap<String, String>();
    //put stuff in the map here.
    painItems.add(map);
    adapter.notifyDataSetChanged();

}
simpledapter适配器;
List-items=new-ArrayList();
ListView listthings;
int[]至;
字符串[]来自;
私有void addItem(){
HashMap=newHashMap();
//把东西放在地图上。
添加(地图);
adapter.notifyDataSetChanged();
}
我想知道我是否能够在列表的某个位置而不是在列表的末尾添加项目。这似乎不应该太难,但我可能遗漏了一些基本的东西


感谢您的帮助和干杯。

您正在寻找痛苦物品。添加(索引、地图)

其中index是要添加元素的位置。所有元素都将移动一个位置,其新索引将为索引+1

您必须小心,因为如果索引大于当前大小,此方法将抛出一个
IndexOutOfBoundsException


)

您正在查找痛苦项目。添加(索引、地图)

其中index是要添加元素的位置。所有元素都将移动一个位置,其新索引将为索引+1

您必须小心,因为如果索引大于当前大小,此方法将抛出一个
IndexOutOfBoundsException


)

是,只需使用重载版本的add:

myList.add(myPosition, myItem)

是的,只需使用重载版本的add:

myList.add(myPosition, myItem)

谢谢你的回答,我喜欢你对安卓本身的独特性。非常简洁!谢谢你的回答,我喜欢你对安卓本身的独特性。非常简洁!