首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >递增/递减列表查看通知上的选定位置decrement

递增/递减列表查看通知上的选定位置decrement
EN

Stack Overflow用户
提问于 2013-05-29 15:14:37
回答 2查看 1.1K关注 0票数 0

嗨!我正在尝试在listview中添加一些值,并尝试使用(inc)和(dec)按钮来增加/减少项目的数量。

若要增加或减少列表视图条目数量,必须选择列表行(如果我在其中添加了任何条目)。

如何在通知上递增/递减listview选中的位置?

现在我是这样做的:

代码语言:javascript
复制
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
    index = position;

}

获取此处选择的指标,并使用该索引值来增加或减少项目数量

EN

回答 2

Stack Overflow用户

发布于 2013-05-29 15:20:38

ListView中填满了您提供给适配器的数据集。如果要增加/减少ListView显示的项目,则必须在此数据集中添加/移除项目并调用notifyDatasetChanged()

票数 0
EN

Stack Overflow用户

发布于 2013-05-29 16:13:20

代码语言:javascript
复制
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();

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16807676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档