Android的:如何从一个ListView和arrayAdapter删除项目 [英] Android: how to remove an item from a listView and arrayAdapter

查看:113
本文介绍了Android的:如何从一个ListView和arrayAdapter删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ArrayList项目的集合。我将它们添加到客户适配器如下:

I have a collection of items in an ArrayList. I add them to a customer adapter as follows:

this.m_adapter = new MyAdapter(this, R.layout.myitem,
    itemCart.m_items);

我对每一个在我的名单上这些项目的删除按钮,但我不知道如何连接删除按钮的的onClick()与在原始项目ArrayList的。有人可以解释如何做到这一点,或点我一个教程,我可以在这读了?非讽刺/不居高临下的反应是极大的AP preciated。

I have a delete button for each of these items in my list, but I am not sure how to connect the delete button's onClick() with the original item in the ArrayList. Can someone please explain how to do this or point me to a tutorial where I can read up on this? Non-sarcastic/non-condescending responses are greatly appreciated.

推荐答案

下面是我的解决方案至今:

Here's my solution so far:

getView()方法,我做这样的事情:

In the getView() method I do something like this:

deleteButton.setTag(position);

看起来 getTag()返回一个对象。所以我转换了位置INT到一个Integer对象第一。它似乎是工作。

It looks like getTag() returns an Object. So I converted the position int into an Integer object first. It appears to be working.

OnClickListener()我做到以下几点:

items.remove(index.intValue());

到目前为止,一切都很好。

So far, so good.

这篇关于Android的:如何从一个ListView和arrayAdapter删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆