Your List is filled up with some data like this,
ArrayList<HashMap<String, String>> arrayList = new ArrayList<HashMap<String, String>>();
for(int i = 1; i <= list.size(); i++){
HashMap<String, String> map = new HashMap<String, String>();
map.put("rowid", "" + i);
map.put("col_1",list.get());
map.put("col_2", map.get(list.get(i-1)));
map.put("col_3", "X");
arrayList.add(map);
}
// fill in the list item layout
adapter = new SimpleAdapter(this, fillMaps, android.R.layout.simple_list_item_1, from, to);
lv.setAdapter(adapter);
}
buttonAdd.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//Here we are adding data to list
int size=list.size();
HashMap<String, String> map = new HashMap<String, String>();
map.put("rowid", "" + size);
map.put("col_1",list.get(size-1));
map.put("col_2", map.get(list.get(size-1)));
map.put("col_3", "X");
arraylist.add(map);
adapter.notifyDataSetChanged();//refreshing adapter
});
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View v,
int index, long arg3) {
//Here we are removing data from list
listview.remove(index);
arrayList.remove(index);
adapter.notifyDataSetChanged();
}
使用'爲setSelection(INT位置)'http://developer.android.com/ reference/android/widget/ListView.html#setSelection(int) –
@Dev Soman是的我使用自定義適配器來設置列表項目 – Bora