Random button Android project - java

I want to make an app that when you click a button it will go to a random place on the screen. I want it to be an ImageButton the when onClick well go to a random place on the screen. I've attempted before. But to no success. Here is some of the code I've already attempted with. --->
package com.example.e99900004533.candycollector;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.graphics.Point;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Display;
import android.view.ViewGroup.MarginLayoutParams;
import android.animation.ObjectAnimator;
import android.widget.RelativeLayout;
import android.widget.EditText;
import android.widget.ImageButton;
import java.util.Random;
public class MainActivity extends ActionBarActivity {
public EditText collectedTextEdit;
public ImageButton candyEdit;
public int collected = 0;
public int screenWidth = 300;
public int screenHeight = 300;
Random random = new Random();
public boolean running = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
collectedTextEdit = (EditText) findViewById(R.id.collectedText);
candyEdit = (ImageButton) findViewById(R.id.candy);
collectedTextEdit.setText("Collected: " + collected);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
addListenerOnButton();
}
public void addListenerOnButton() {
candyEdit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
collected += 1;
collectedTextEdit.setText("Collected: " + collected);
int candyX = random.nextInt(screenWidth - 50);
int candyY = random.nextInt(screenHeight - 50);
System.out.println(candyX + " : " + candyY);
MarginLayoutParams marginParams = new MarginLayoutParams(candyEdit.getLayoutParams());
marginParams.setMargins(candyX, candyY, 0, 0);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
candyEdit.setLayoutParams(layoutParams);
//if (candyX > screenWidth) {
//screenWidth -= 50;
//layoutParams.setMargins(candyX, candyY, candyX, LayoutParams.WRAP_CONTENT);
//candyEdit.setLayoutParams(layoutParams);
//}
//if (candyY > screenHeight) {
//screenHeight -= 50;
//layoutParams.setMargins(candyX, candyY, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//candyEdit.setLayoutParams(layoutParams);
//}
//while (running == true) {
//candyY -= 1;
//layoutParams.setMargins(candyX, candyY, candyX, candyY);
//candyEdit.setLayoutParams(layoutParams);
//}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

I hope you are using Android Studio as it gives you a beautiful way of accessing all the benefits of the Android API.
Anyway, before I post the code, you set the onClickListener within your java code and while that is fine, it can clutter up your code. A much more aesthetically pleasing solution is to use XML and a button's android:onClick. You will see this in the code.
Java:
package testinc.com.randombutton;
import android.graphics.Point;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.*;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.Random;
public class MainActivity extends ActionBarActivity {
// Encapsulating the data just to be safe...
private int collected = 0;
private int screenWidth = 300;
private int screenHeight = 300;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
TextView collectedView = (TextView) findViewById(R.id.collectedTV);
collectedView.setText("Collected: " + collected);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void toRandomPosition(View view) {
// Based on our collection candy collection:
collected += 1;
TextView collectedView = (TextView) findViewById(R.id.collectedTV);
collectedView.setText("Collected: " + collected);
// Based on position of our candy:
Random random = new Random();
// Understand nextInt(N) will go from 0 -> N-1, also are you trying to control where it can go?
float candyX = (float) random.nextInt(screenWidth - 50);
float candyY = (float) random.nextInt(screenHeight - 50);
// I didn't write it, but you need to check these float values if they exceed the screen width and the screen length. */
// Sout to check coordinates
System.out.println(candyX + " : " + candyY);
// To change margins:
ImageButton imgButton = (ImageButton) findViewById(R.id.changePlace);
imgButton.setX(candyX);
imgButton.setY(candyY);
}
}
Android:
Note: I used a linear layout because I dislike the relative. You can change it without repercussions I suppose.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView android:id="#+id/collectedTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageButton android:id="#+id/changePlace"
android:onClick="toRandomPosition"
android:contentDescription="It's a button, ha za"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Key parts:
android:onClick="toRandomPosition" hooks up with the method, public void toRandomPosition(View view)
setX and setY require floating point numbers to set the position. Unfortunately, it seems that the random class does not have nextFloat(float n) in its class. I recommend just casting the int as a float for now.
Seeing that I am doing this now, here is a possible (I have not checked it) solution to the coordinates going beyond the bounds of the screen:
while ( candyX >= screenWidth || candyY >= screenHeight) {
candyX = (float) random.nextInt(screenWidth - 50);
candyY = (float) random.nextInt(screenHeight - 50);
}
I checked if the position was equal because a button at the corner of the screen is a pain to find and may be skewed off the display.

Related

How to swap the position of two buttons in android?

I am creating a a puzzle match game where in order to match two buttons together you must swap the position of them. for example, i want to swap the position of button1 with the position that button2 is in. Anybody have any suggestions?
Here is my code below:
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import java.util.ArrayList;
import java.util.Collections;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class puzzle extends ActionBarActivity {
private TextView moveCounter;
private TextView feedbackText;
private Button[] buttons;
private Boolean bad_move=false;
// private static final Integer[] goal = new Integer[] {0,1,2,3,4,5,6,7,8};
// private String [][] puz = new String [3][3];
Button b [][];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_puzzle);
swap();
}
private void setBoard(){
b = new Button[3][3];
b[0][0]= (Button).findViewById(R.id.button1);
b[0][1]= (Button).findViewById(R.id.button2);
b[0][2] = (Button).FindById(R.id.button3);
b[1][0] = (Button).FindBdyId(R.id.button4);
b[1][1] = (Button).FindById(R.id.button5);
b[1][2] = (Button).FindById(R.id.button6);
b[2][0] = (Button).FindById(R.id.button7);
b[2][1] = (Button).FindById(R.id.button8);
b[2][2] = (Button).FindById(R.id.button9);
}
private void swap() {
b.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_puzzle, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
If you are using API level greater than 11, you can use getX() and getY() to get coordinates of a button.
And setX() and setY() to set a button in a particular coordinate.
for example,
// getting coordinates of button
float posX = button.getX();
float posY = button.getY();
// setting button2 in the coordinates that we got above
button2.setX(posX);
button2.setY(posY);
The way I've gotten this work is similar to your approach you had originally posted. Try giving this a shot:
Button btnOne = (Button) findViewById(R.id.buttonOne);
Button btnTwo = (Button) findViewById(R.id.buttonTwo);
float posOneX = btnOne.getX();
float posOneY = btnOne.getY();
float posTwoX = btnTwo.getX();
float posTwoY = btnTwo.getY();
btnOne.setX(posTwoX);
btnOne.setY(posTwoY);
btnTwo.setX(posOneX);
btnTwo.setY(posOneY);

Margin's distort image size

When I'm setting the margins of this ImageButton, it distorts the size of the image. Why is this happening?
Code:
package com.example.e99900004533.candycollector;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.graphics.Point;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Display;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.LinearLayout;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.EditText;
import android.widget.ImageButton;
import java.util.Random;
public class MainActivity extends ActionBarActivity {
public EditText collectedTextEdit;
public ImageButton candyEdit;
public int collected = 0;
public int screenWidth = 300;
public int screenHeight = 300;
Random random = new Random();
public boolean running = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
collectedTextEdit = (EditText) findViewById(R.id.collectedText);
candyEdit = (ImageButton) findViewById(R.id.candy);
collectedTextEdit.setText("Collected: " + collected);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
addListenerOnButton();
}
public void addListenerOnButton() {
candyEdit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
collected += 1;
collectedTextEdit.setText("Collected: " + collected);
int candyX = random.nextInt(screenWidth - 50);
int candyY = random.nextInt(screenHeight - 50);
System.out.println(candyX + " : " + candyY);
MarginLayoutParams marginParams = new MarginLayoutParams(candyEdit.getLayoutParams());
marginParams.setMargins(candyX, candyY, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams);
candyEdit.setLayoutParams(layoutParams);
if (candyX > screenWidth) {
screenWidth -= 50;
layoutParams.setMargins(candyX, candyY, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
candyEdit.setLayoutParams(layoutParams);
}
if (candyY > screenHeight) {
screenHeight -= 50;
layoutParams.setMargins(candyX, candyY, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
candyEdit.setLayoutParams(layoutParams);
}
//while (running == true) {
//candyY -= 1;
//layoutParams.setMargins(candyX, candyY, candyX, candyY);
//candyEdit.setLayoutParams(layoutParams);
//}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is the ImageButton code:
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/candy"
android:background="#drawable/candy"
android:contentDescription="#string/candyImg"
android:clickable="true"
android:layout_below="#+id/collectedText"
android:layout_alignRight="#+id/collectedText"
android:layout_alignEnd="#+id/collectedText" />
Also can anyone explain, or give resources, on how setting margins really works. BTW using Android Api level 15 - 22.
Please Help!

Java Shake Not Executing... why?

Alright, I've fought with this for a week or so, but I'm confident that it's a simple fix. I'm new to Android development and am using a fair bit of shared code, so there is likely something I'm missing. This is a simple app that parse's news headlines from RealClearPolitics.com. It executes on a button just fine, so I know the parsing backend, and new text display are working fine. But when I try to use the same kind of set up for a shake, it doesn't work. I believe the issue is in the handshake between my MainActivity class and the ShakeEventListener, or how I'm executing the ShakeEventListener. I've followed online direction to the best I can, but am stuck. Any pointers? Here's my full code for reference sake, with suspected problem blocked by ------.
MainActivity:
package com.example.gregoriovasquez.rcpparse;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.StrictMode;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.*;
import android.widget.Button;
import android.widget.TextView;
import static android.view.View.*;
public class MainActivity extends ActionBarActivity implements OnClickListener{
Button button_name;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private ShakeEventListener mShakeEventListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//button properties
button_name= (Button) findViewById(R.id.button1);
button_name.setOnClickListener(MainActivity.this);
if (android.os.Build.VERSION.SDK_INT > 9)
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
**----------------------------------------------------------------------------
*// ShakeDetector initialization
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mShakeEventListener = new ShakeEventListener();
mShakeEventListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {
#Override
public void onShake(int count) {
handleShakeEvent(count)
});*
}
public void handleShakeEvent(int count){
TextView rootView = (TextView) findViewById(R.id.mytextView);
rootView.setText(TextMatcher.PatternReturn());
}
**---------------------------------------------------------------------------
#Override
public void onClick(View v){
TextView rootView = (TextView) findViewById(R.id.mytextView);
rootView.setText(TextMatcher.PatternReturn());
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(mShakeEventListener, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}
#Override
protected void onPause() {
mSensorManager.unregisterListener(mShakeEventListener);
super.onPause();
}
}
ShakeEventListener:
package com.example.gregoriovasquez.rcpparse;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.FloatMath;
public class ShakeEventListener implements SensorEventListener {
private static final float SHAKE_THRESHOLD_GRAVITY = 2.7F;
private static final int SHAKE_SLOP_TIME_MS = 500;
private static final int SHAKE_COUNT_RESET_TIME_MS = 3000;
private OnShakeListener mListener;
private long mShakeTimestamp;
private int mShakeCount;
public void setOnShakeListener(OnShakeListener listener) {
this.mListener = listener;
}
public interface OnShakeListener {
public void onShake(int count);
}
#Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// ignore
}
#Override
public void onSensorChanged(SensorEvent event) {
if (mListener != null) {
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
float gX = x / SensorManager.GRAVITY_EARTH;
float gY = y / SensorManager.GRAVITY_EARTH;
float gZ = z / SensorManager.GRAVITY_EARTH;
// gForce will be close to 1 when there is no movement.
float gForce = FloatMath.sqrt(gX * gX + gY * gY + gZ * gZ);
if (gForce > SHAKE_THRESHOLD_GRAVITY) {
final long now = System.currentTimeMillis();
// ignore shake events close to each other
if (mShakeTimestamp + SHAKE_SLOP_TIME_MS > now) {
return;
}
// reset the shake count after no shakes
if (mShakeTimestamp + SHAKE_COUNT_RESET_TIME_MS < now) {
mShakeCount = 0;
}
mShakeTimestamp = now;
mShakeCount++;
mListener.onShake(mShakeCount);
}
}
}
}
And the Following in my Manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />

Change android textview color with number picker Integer

I am new to android and I am just dipping my toes in with is. I want to have number picker define what the color of text is. This is the code for the number picker so far.
package nathan.nathan;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.NumberPicker;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
TextView numberView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
numberView = (TextView)findViewById(R.id.numberview);
NumberPicker numberPicker = (NumberPicker) findViewById(R.id.numberPicker);
numberPicker.setMaxValue(100);
numberPicker.setMinValue(0);
numberPicker.setWrapSelectorWheel(true);
numberPicker.setOnValueChangedListener( new NumberPicker.
OnValueChangeListener() {
#Override
public void onValueChange(NumberPicker picker, int
oldVal, int newVal) {
numberView.setText("I am "+
newVal);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I'm just confused on what to do. Help would be much appreciated! :)
It's up to you how you'd like to map your integer from 0 to 100 to a color, but here's one way to do it:
numberPicker.setOnValueChangedListener(
new NumberPicker.OnValueChangeListener() {
#Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
numberView.setText("I am " + newVal);
int color;
if (newVal < 30) {
color = Color.parseColor("#ff0000");
} else if (newVal < 60) {
color = Color.parseColor("#00ff00");
} else {
color = Color.parseColor("#0000ff");
}
numberView.setTextColor(color);
}
});
See the TextView.setTextColor() documentation.

Converting a double to a string for a radio button

I have not been able to figure out but what im trying to do is convert a couple double variables in my application to a string. Im not exactly sure how to do that in my current code. I keep getting a "cannot invoke isChecked() on the primitive type double". I wasnt able to find any tutorial explaining how to do this so forgive me. Here is my code, any tips would be appreciated :
package net.androidbootcamp.zipcarrentalapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity
{
private RadioGroup radioGroupId;
private RadioButton radioButton;
private Button button;
final RadioButton Compact = (RadioButton)findViewById(R.id.radCompact);
final RadioButton MidSize = (RadioButton)findViewById(R.id.radMidSize);
final RadioButton Luxury = (RadioButton)findViewById(R.id.radLuxury);
final TextView result = (TextView) findViewById(R.id.txtResult);
double radCompact = 59.99;
double radMidSize = 65.99;
double radLuxury = 89.99;
int days = 0;
double computeValue;
public void operation(int days)
{
if(days <= 10)
{
if(radCompact.isChecked())
{
computeValue = radCompact * days;
txtResult.setText("Cost:" + Double.toString(computeValue));
}
else if (radMidSize.isChecked())
{
computeValue = radMidSize * days;
txtResult.setText("Cost: " + Double.toString(computeValue));
}
else if (radLuxury.isChecked())
{
computeValue = radLuxury * days;
txtResult.setText("Cost:" + Double.toString(computeValue));
}
}
}
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
Your code is a little bit off. You have three buttons,
final RadioButton Compact = (RadioButton)findViewById(R.id.radCompact);
final RadioButton MidSize = (RadioButton)findViewById(R.id.radMidSize);
final RadioButton Luxury = (RadioButton)findViewById(R.id.radLuxury);
You call isChecked() on them. For example, this
if(radCompact.isChecked())
should be
if (Compact.isChecked())
and then
else if (MidSize.isChecked())
and finally
else if (Luxury.isChecked())
Edit And,
final TextView result = (TextView) findViewById(R.id.txtResult);
should be
final TextView txtResult = (TextView) findViewById(R.id.txtResult);
You could try to typecast the variable to the Double object.
Something like:
((Double) computeValue).toString

Categories