Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 1st, 2012, 11:45 AM
Z_Dom16 Z_Dom16 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 4 Z_Dom16 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 34 sec
Reputation Power: 0
Android Yahtzee

why won't my commented code work???


YahtzeeActivity.Java


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ImageSwitcher;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.view.KeyEvent;
import java.util.Random;


public class YahtzeeActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.main);


OnClickListener button_Listener = new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(), ((ImageButton) v).getId() + " was clicked", Toast.LENGTH_LONG).show();
}
};


OnClickListener button_Listener_ = new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(), ((Button) v).getText() + " was clicked", Toast.LENGTH_LONG).show();
}
};



// ImageButton button1_ = (ImageButton) findViewById(R.id.red_1_dice);
//
// button1_.setOnClickListener(new OnClickListener()
// {
// public void onClick(View v)
// {
// Toast.makeText(getBaseContext(), ((ImageButton) v).getContext()+ " was clicked", Toast.LENGTH_LONG).show();
//
// if(button1_.isClickable() == true)
// {
// Random random = new Random();
// int random_number = random.nextInt(6) + 1;
//
// if(random_number == 1)
// {
// ImageButton button1_new_button = (ImageButton)findViewById(R.id.red_1_dice);
// button1_ = button1_new_button;
// }
// }
// }
// });


ImageButton button1_ = (ImageButton)findViewById(R.id.red_1_dice);
button1_.setOnClickListener(button_Listener);

ImageButton button2_ = (ImageButton)findViewById(R.id.red_2_dice);
button2_.setOnClickListener(button_Listener);

ImageButton button3_ = (ImageButton)findViewById(R.id.red_3_dice);
button3_.setOnClickListener(button_Listener);

ImageButton button4_ = (ImageButton)findViewById(R.id.red_4_dice);
button4_.setOnClickListener(button_Listener);

ImageButton button5_ = (ImageButton)findViewById(R.id.red_5_dice);
button5_.setOnClickListener(button_Listener);

// ImageButton button6_ = (ImageButton)findViewById(R.id.red_6_dice);
// button6_.setOnClickListener(button_Listener);

Button reroll_button = (Button)findViewById(R.id.Reroll_Button);
reroll_button.setOnClickListener(button_Listener_) ;

Button hold_button = (Button)findViewById(R.id.Hold_Button);
hold_button.setOnClickListener(button_Listener_);

}
}


main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout

xmlns:android=
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidrientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<ImageButton
android:id="@+id/red_1_dice"
android:text="red 1 dice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft = "300px"
android:layout_marginTop = "60px"
android:src="@drawable/red_1_dice" />

<ImageButton
android:id="@+id/red_2_dice"
android:text="red 2 dice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft = "40px"
android:layout_marginTop = "-134px"
android:src="@drawable/red_2_dice" />

<ImageButton

android:id = "@+id/red_3_dice"
android:text="red 3 dice"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_marginTop = "20px"
android:layout_marginLeft = "160px"
android:src = "@drawable/red_3_dice"/>

<ImageButton

android:id = "@+id/red_4_dice"
android:text="red 4 dice"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_marginLeft = "300px"
android:src = "@drawable/red_4_dice"/>

<ImageButton
android:id="@+id/red_5_dice"
android:text="red 5 dice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop = "-125px"
android:layout_marginLeft = "30px"
android:src="@drawable/red_5_dice"/>

<Button
android:id="@+id/Reroll_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20px"
android:layout_marginTop="60px"
android:text="Reroll Selected Dice" />

<Button
android:id = "@+id/Hold_Button"
android:text = "Hold All Dice"
android:layout_width = "wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop = "-74px"
android:layout_marginLeft = "300px" />

</LinearLayout>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Android Yahtzee


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap