嗨!我正在尝试在listview中添加一些值,并尝试使用(inc)和(dec)按钮来增加/减少项目的数量。
若要增加或减少列表视图条目数量,必须选择列表行(如果我在其中添加了任何条目)。
如何在通知上递增/递减listview选中的位置?
现在我是这样做的:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
index = position;
}获取此处选择的指标,并使用该索引值来增加或减少项目数量
发布于 2013-05-29 15:20:38
ListView中填满了您提供给适配器的数据集。如果要增加/减少ListView显示的项目,则必须在此数据集中添加/移除项目并调用notifyDatasetChanged()
发布于 2013-05-29 16:13:20
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();
}https://stackoverflow.com/questions/16807676
复制相似问题