Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

setText() with getId()?

 
Ranch Hand
Posts: 87
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I use setText() with the return value of v.getId()? I have some TextView fields. I would like to examine which was clicked, than call a function with the clicked TextView's ID as a parameter.
How can I do this? I have got some error messages.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the ranch!

It isn't clear what you want to do. Could you describe more detail about what you need, provide some sample code (please read UseCodeTags before posting code) and show the errors you are getting?
 
Kovacs Akos
Ranch Hand
Posts: 87
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a lot of TextViews and I would like to know which was clicked. I am using onclicklistener, but I would like to call a function with the Id of the clicked textview and then use a setText().

This is the error message:
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An id is an int, not a TextView. I am still not clear what you are trying to do. Please show the code.

You need to call setText() on the TextView, not the TextView's id. If you get a View and are sure it is a TextView, you could do ((TextView)view).setText(...). This casts the view to a TextView, so you have access to the setText() method. But I am not sure what the id has to do with it...
 
Kovacs Akos
Ranch Hand
Posts: 87
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see the code: http://paste.ubuntu.com/6232871/
 
Rancher
Posts: 43075
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why involve the ID when you have a reference to the actual View? You can do it like Steve suggested: ((TextView) v).setText(...).
 
Kovacs Akos
Ranch Hand
Posts: 87
1
Netbeans IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Why involve the ID when you have a reference to the actual View? You can do it like Steve suggested: ((TextView) v).setText(...).



Thanks and thanks also Steve, it is working!
 
Your mother was a hamster and your father was a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic