• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

Android Development: Simple textbox with submit button

I've created my textbox and my submit button on the main.xml.

I'm trying to store the textbox value (in this case, let's make it someone's name) after hitting the button to a string variable.

Whenever I try to create the entry though, it makes it an integer even though I'm finding it under R.string.someonesname

Any  help?
0
Dale Harris
Asked:
Dale Harris
  • 3
1 Solution
 
Dale HarrisAuthor Commented:
This is what I have so far:

        Button button = (Button) findViewById(R.id.button1);
    	button.setOnClickListener(new onClick() {
    		@Override
    	   public void onClick(View v) {
    	      // button 1 was clicked!

Open in new window


It's giving me a lot of errors in the way that I'm using it.  It can store the button, no problem, but when I try to set the onclicklistener, that's what it bombs out.

In my tests, I was able to set the textbox value, but the button is not being "clicked" to do anything.
0
 
Dale HarrisAuthor Commented:
I found the solution only 20 minutes later:

The import won't automatically find the right one, so you have to add:

import android.view.View.OnClickListener;

Then here's the exact working syntax:

        Button button = (Button) findViewById(R.id.button1);
          button.setOnClickListener(new OnClickListener()
          {
             public void onClick(View v)
                {
                // button 1 was clicked!
0
 
Dale HarrisAuthor Commented:
This is harder than it looks people...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now