Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old October 6th, 2012, 09:48 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Oct 2012
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default My buttons won't work...

I have been trying for the last 3-4 days to get my buttons to work and I can't figure out what my problem is. I feel like it is so simple, yet I just don't see it.

Current task:
Getting the buttons to display a Toast message so that I can ensure the buttons are working.

Next task:
Create an increase and decrease counter......first things first though

I appreciate the help.

Code:
package com.sports.discgolfou;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class hole_1 extends Activity implements View.OnClickListener{

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page2);
        
		//TextView SC = (TextView) findViewById(R.id.labelShotCounter);
		Button ButtonAdd = (Button) findViewById(R.id.buttonAdd);
		ButtonAdd.setOnClickListener(this);
		Button ButtonMinus = (Button) findViewById(R.id.buttonMinus);
		ButtonMinus.setOnClickListener(this);
		
	}//End onCreate	


	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId() == R.id.buttonAdd)
		{
			Toast.makeText(this, "Hello World", Toast.LENGTH_LONG).show();
		}
		else if(v.getId() == R.id.buttonMinus)
		{
			Toast.makeText(this, "GoodBye World", Toast.LENGTH_LONG).show();
		}
			
		
	}//End onClick
	
	
	
}//End Activity

Advertisements
DragonRider71 is offline  
Reply With Quote
sponsored links
Old October 18th, 2012, 03:06 PM   #2 (permalink)
Junior Member
 
olijf's Avatar
 
Join Date: Sep 2012
Location: Rotterdam, Holland
Gender: Male
Posts: 19
 
Device(s): Samsung Galaxy S3
Carrier: Not Provided

Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Skype™ to olijf dewitte.joost@gmail.com
Default

did you set the button property's right?
onClick : onClick
and clickable checked.

if that isnt it, post your layout.xml.
we can't really see what's going on now.

EDIT: make sure you named everything EXACTLY right. uppercase lowercase etc.
olijf is offline  
Reply With Quote
Old October 19th, 2012, 08:53 AM   #3 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,935
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 482 Times in 294 Posts
Default

Your code is correct and should work. The only thing I can guess that might be the problem is that your ids that you are referencing are not the right ids. Can you post your layout xml?
__________________
My blog, Inverted Keystrokes, is looking for aspiring developers (not necessarily with Android) to post articles. If you have any development experience and are interested in participating, please PM me. =)
jonbonazza is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:00 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.