[android-developers] Re: how to remove an item from a listView and arrayAdapter

2011-01-15 Thread gonzobrains
Thanks for the answer.  I had a feeling the Tag property was involved
somehow, but what's the right way to use it?  In the getView() method
can I do something like this:

deleteButton.setTag(position);

where position is the int passed into getView()?  And then use that in
the delete button's OnClickListener()?  It looks like getTag() returns
an Object.

I just tried passing an Integer object in the Tag property.  It
appears to be working.

In the OnClickListener() I do the following:

items.remove(index.intValue());

Is this the standard recommended way to do this?  I just want to make
sure there aren't any gotchas I have missed as a result of taking this
approach.

Thanks again,
gb

On Jan 14, 11:24 pm, TreKing  wrote:
> On Sat, Jan 15, 2011 at 12:48 AM, gonzobrains  wrote:
> > 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.
>
> You have a getView() method where you build these custom items, I assume.
> You could set the Tag property on each button with the index it's for, then
> when you click the button just pull it out and use that to index.
>
> > Non- sarcastic/non-condescending responses are greatly appreciated.
>
> You're no fun.
>
> --- 
> --
> TreKing  - Chicago
> transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: how to remove an item from a listView and arrayAdapter

2011-01-15 Thread Doug
On Jan 14, 11:24 pm, TreKing  wrote:
> On Sat, Jan 15, 2011 at 12:48 AM, gonzobrains  wrote:
> > 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.
>
> You have a getView() method where you build these custom items, I assume.
> You could set the Tag property on each button with the index it's for, then
> when you click the button just pull it out and use that to index.

You could also just make the position int final and use it in the
View.OnClickListener.onClick that you assign to the button in
getView.  Or if you don't want to define the listener inline, just
pass the int to the constructor of the implementation of
View.OnClickListener you create and save the int as a member of that
instance.

Doug

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: how to remove an item from a listView and arrayAdapter

2011-01-15 Thread TreKing
On Sat, Jan 15, 2011 at 2:07 PM, gonzobrains  wrote:

> I had a feeling the Tag property was involved somehow, but what's the right
> way to use it?
>

The "right" way is dependent on your use case. It's there specifically as a
convenience for you to attach arbitrary data to your view.


> In the getView() method can I do something like this:
>
> deleteButton.setTag(position);
>
> where position is the int passed into getView()?
>

Correct.


> And then use that in the delete button's OnClickListener()?
>

Correct.


> It looks like getTag() returns an Object.
>

Correct.


> I just tried passing an Integer object in the Tag property.  It appears to
> be working.
>

Correct.


> In the OnClickListener() I do the following:
>
> items.remove(index.intValue());
>
> Is this the standard recommended way to do this?
>

I don't know about "standard recommended" but it's the first thing I thought
of. If you want some inner object to know which row it's in, seems as good a
way as any.


> I just want to make sure there aren't any gotchas I have missed as a result
> of taking this approach.
>

None that I'm aware of.

-
TreKing  - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en