Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setText() with getId()?

 
Kovacs Akos
Ranch Hand
Posts: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • 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: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see the code: http://paste.ubuntu.com/6232871/
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • 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: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic