• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EventHandling not working with button

 
vinoth vino
Ranch Hand
Posts: 67
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
Simon Roberts
Author
Ranch Hand
Posts: 170
7
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
Ron McLeod
Bartender
Pie
Posts: 1049
65
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic