Views have a dedicated field you can use to store your own
identifiers.

You should put some value that uniquely identifies the view into it's
'tag' member "setTag(Object)".  This member is there for you to put
just this kind of info into.

Then, when you get the onClick event with the view, just cast the
'getTag()' to the appropriate object type... tada!

Couple of examples:

* I store a Long in the tag that corresponds to the "_ID" column in
the table row the view models
* If it's a manually generated or otherwise 'disconnected' object you
could store the object itself in there, using the ListActivity as
your.... list!

Doug


On Aug 23, 2:13 pm, Croccy22 <matthew.bea...@gmail.com> wrote:
> Hi thanks for the reply,
>
> I've set an onClickListener and it's only parameter is View. The
> problem is  don't know how to translate that information back to a
> useful identifier. I can't use getID ecause the buttons are all
> created from the same XML layout so they have the same ID. The only
> unique thing I can find is if I do a v.toString() tis returns somehing
> like android.widget.but...@123456.
>
> What I need to do is if I press a button in the second View of the
> ListView I need to retrieve a value from a cursor database from the
> second result?
>
> Matt.
>
> On Aug 21, 6:53 pm, skink <psk...@gmail.com> wrote:
>
>
>
> > On Aug 21, 10:18 am, Croccy22 <matthew.bea...@gmail.com> wrote:
>
> > > Hi all,
>
> > > I am writing  a program where I need a ListView for which I am using a
> > >ListActivity. Each one  of the views within the ListView has four
> > > buttons, (Off, Dim, Bright and On). Each one of these buttons is
> > > configured with it's own OnClickListener when I build the view. This
> > > part seems to work  ok.
>
> > > However when I have say 5 Views each which has these four buttonns, I
> > > cann tell whether an off,dim,bright or onbuttonwas pressed but I
> > > cannot tell from which view it was pressed.
>
> > > So for example if my views are devices (Light, Heater and Kettle) I
> > > press an "on"buttonand i know an Onbuttonwas pressed but how do I
> > > get it to tell me the Onbuttonfor the Light was pressed?
>
> > > Any ideas on how to achieve this?
>
> > > Thanks, Matt
>
> > well,
>
> > what method does OnClickListener interface  have?
>
> > and what's its only parameter?
>
> > pskink- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to