• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps 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
 
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.
 
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?
 
Back
Top Bottom