• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

EventHandling not working with button

 
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends.... I'm new to Android programming and now i just simply create one button with listener and one multiline text(I searched a lot whether the edittext is available in the right pane but there were no edittext there. so i'm using multiline text in this activity and i've change the layout resource ot text then in that edittext tag is present). if i click this button then i want to display the content which I've set up in the edittext variable

MainActivity.java


AndroidManifest.xml


Activity Main.xml

Thanks in advance
Sorry for my english
Screen-Shot-2015-11-14-at-9.03.00-pm.png
[Thumbnail for Screen-Shot-2015-11-14-at-9.03.00-pm.png]
Screen-Shot-2015-11-14-at-9.13.37-pm.png
[Thumbnail for Screen-Shot-2015-11-14-at-9.13.37-pm.png]
in this img onclicklistener is invisible in the import statement
 
Author
Posts: 311
13
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally, I'd shut up, since I'm not much of an android person. However, as best I recall, the behavior of components in Android mimics that of typical components in "regular Java". If that's the case, then you actually need to a) make the code that includes the cliick handler "implement Xxxx" where Xxxx is the name of the expected listener for the button, and you need to do something like addActionListener(myXxxx) to attach the listener directly to the source of events.

Hope this helps, sorry if it's a total red herring. As I say, I tinkered with Android some years ago, and I vaguely recall it had "the usual structure, Might be embarrassingly wrong though.
 
Marshal
Posts: 4823
604
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to specify a onClick handler for the button - either in the layout file with an android:onClick attribute, or programmatically with the button's setOnClickListener() method.

Take a look at the Button API reference for more information.
 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ron!!! I did it with setOnClickListener method also but i got error only. At last I figured out that I wanna declare the buttons,EditText after the setContentView method. Thanks a lot ron
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic