Error with the if and else statement - android

I am getting 3 different errors: identifier expected, unexpected token, unknown class: 'score'. These error's are in line 57-69.
The point of this code is to check if a checklist is checked and, if so, add 1 to score. It than changes the output text to a different string depending on score.
package xyz.ashraf.whoisdelasalle;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
/**
* Created by Ashraf on 3/2/2016.
*/
public class check_Button extends Pop_sallian{
// Connects The variable to an xml id
TextView output = (TextView) findViewById(R.id.output);
//sets the variable to 0
int score = 0;
public void onCheckboxClicked(View view) {
boolean checked = ((CheckBox) view).isChecked();
switch(view.getId()){
case R.id.concern:
if(checked) {
score += 1;
}
break;
case R.id.faith:
if(checked){
score+=1;
}
break;
case R.id.respect:
if(checked){
score+=1;
}
break;
case R.id.education:
if(checked){
score+=1;
}
break;
case R.id.community:
if(checked){
score+=1;
}
break;
}
}
// adds the variables together to form a score
if(score == 0){
output.setText("Come on! Get involved, your la sallian community needs you.");
} else if( score == 1){
output.setText("Good start, keep going!");
} else if( score == 2){
output.setText("Room to improve but doing good!");
} else if(score == 3){
output.setText("Very good, others look up to you!");
} else if(score == 4){
output.setText("Wow, you really are an inspiration");
} else if(score == 5){
output.setText("Excellent! You're a leader in your la sallian community");
} else{
output.setText("Unknown");
}
// changes the output text based on score value
}
^^ Code where the error is located^^
package xyz.ashraf.whoisdelasalle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
/**
* Created by Ashraf on 1/27/2016.
*/
public class Pop_sallian extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popwindow_sallian);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int)(width*.8),(int)(height*.6));
Button checkButton = (Button) findViewById(R.id.check);
checkButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Pop_sallian.this, check_Button.class));
}
});
Button okButton = (Button) findViewById(R.id.okButton_sallian);
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
}
^^ Code where the pop up screen is launched and where the check button is^^
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you a Sallian?"
android:id="#+id/textView7"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you meet the following prerequisites, if you do you may be a Sallian"
android:id="#+id/textView8"
android:layout_below="#+id/textView7"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textColor="#000000" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you concerened for the poor and Social Justice?"
android:id="#+id/concern"
android:textSize="18sp"
android:layout_below="#+id/textView8"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you have faith in the presence of God?"
android:id="#+id/faith"
android:textSize="15sp"
android:layout_below="#+id/concern"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you have Respect for all people?"
android:id="#+id/respect"
android:layout_below="#+id/faith"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:textSize="15sp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you value education?"
android:id="#+id/education"
android:textSize="15sp"
android:layout_below="#+id/respect"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you inclusive in your community?"
android:id="#+id/community"
android:layout_below="#+id/education"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="15sp"
android:checked="false"
android:onClick="onCheckboxClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:id="#+id/okButton_sallian"
android:layout_below="#+id/community"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="20dp"
android:layout_marginTop="90dp"
android:layout_marginBottom="20dp"
android:background="#FAFAFA"
android:textColor="#00E676"
android:elevation="2dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check"
android:id="#+id/check"
android:textColor="#00E676"
android:elevation="2dp"
android:background="#FAFAFA"
android:layout_alignTop="#+id/okButton_sallian"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/output"
android:textColor="#1eff00"
android:textSize="20sp"
android:layout_below="#+id/community"
android:layout_centerHorizontal="true"
android:layout_above="#+id/check"
android:textIsSelectable="false" />
</RelativeLayout>
</ScrollView>
^^XML code^^

You have the closing curly bracket } in the wrong place. The function was ending before the if.
public void onCheckboxClicked(View view) {
boolean checked = ((CheckBox) view).isChecked();
switch(view.getId()){
case R.id.concern:
if(checked) {
score += 1;
}
break;
case R.id.faith:
if(checked){
score+=1;
}
break;
case R.id.respect:
if(checked){
score+=1;
}
break;
case R.id.education:
if(checked){
score+=1;
}
break;
case R.id.community:
if(checked){
score+=1;
}
break;
}
// adds the variables together to form a score
//} <-- REMOVE THIS CURLY BRACKET
if(score == 0){
output.setText("Come on! Get involved, your la sallian community needs you.");
} else if( score == 1){
output.setText("Good start, keep going!");
} else if( score == 2){
output.setText("Room to improve but doing good!");
} else if(score == 3){
output.setText("Very good, others look up to you!");
} else if(score == 4){
output.setText("Wow, you really are an inspiration");
} else if(score == 5){
output.setText("Excellent! You're a leader in your la sallian community");
} else{
output.setText("Unknown");
}
// changes the output text based on score value
} // <-- MOVE THE CURLY BRACKET HERE

Related

How to pass checked and unchecked checkbox value to another Activity in Android?

This is my working code for passing checked and unchecked checkbox value to another Activity:
This is First Activity image.
FIRST ACTIVITY Image
This is Second Activity Image.
SECOND ACTIVITY Image
1.This is First Activity xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.himanshu.checkbox_module.FirstActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Activity"
android:textSize="20dp"
android:textColor="#f00"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monday"
android:onClick="onCheckedBox"
android:id="#+id/mon"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tuesday"
android:onClick="onCheckedBox"
android:id="#+id/tue"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wednesday"
android:onClick="onCheckedBox"
android:id="#+id/wed"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thursday"
android:onClick="onCheckedBox"
android:id="#+id/thu"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friday"
android:onClick="onCheckedBox"
android:id="#+id/fri"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Saturday"
android:onClick="onCheckedBox"
android:id="#+id/sat"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sunday"
android:onClick="onCheckedBox"
android:id="#+id/sun"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="send to second activity"
android:layout_marginTop="20dp"
android:id="#+id/button1"/>
</LinearLayout>
2.This is First Activity java file.
package com.example.himanshu.checkbox_module;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextClock;
public class FirstActivity extends AppCompatActivity {
Intent intentData;
Button buttonSend;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
intentData = new Intent(FirstActivity.this,SecondActivity.class);
buttonSend = (Button) findViewById(R.id.button1);
buttonSend.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(intentData);
}
});
}
public void onCheckedBox(View view){
boolean checked = ((CheckBox)view).isChecked();
switch (view.getId()){
case R.id.mon:if (checked){
intentData.putExtra("MON","Monday");
}else {
intentData.removeExtra("MON");
}break;
case R.id.tue:if (checked){
intentData.putExtra("TUE","Tuesday");
}else {
intentData.removeExtra("TUE");
}break;
case R.id.wed:if (checked){
intentData.putExtra("WED","Wednesday");
}else {
intentData.removeExtra("WED");
}break;
case R.id.thu:if (checked){
intentData.putExtra("THU","Thursday");
}else {
intentData.removeExtra("THU");
}break;
case R.id.fri:if (checked){
intentData.putExtra("FRI","Friday");
}else {
intentData.removeExtra("FRI");
}break;
case R.id.sat:if (checked){
intentData.putExtra("SAT","Saturday");
}else {
intentData.removeExtra("SAT");
}break;
case R.id.sun:if (checked){
intentData.putExtra("SUN","Sunday");
}else {
intentData.removeExtra("SUN");
}break;
default:break;
}
}
}
3.This is Second Activity xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_secon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.himanshu.checkbox_module.SecondActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Activity"
android:textSize="20dp"
android:textColor="#f00"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textview_result"
android:textColor="#000000"
android:textSize="15dp"
android:textAllCaps="true"
android:layout_marginTop="20dp"/>
</LinearLayout>
4.This is Second Activity java file.
package com.example.himanshu.checkbox_module;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends AppCompatActivity {
TextView showResult;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_secon);
showResult = (TextView) findViewById(R.id.textview_result);
Intent intentResult = this.getIntent();
String monday = intentResult.getStringExtra("MON");
String tuesday = intentResult.getStringExtra("TUE");
String wednesday = intentResult.getStringExtra("WED");
String thursday = intentResult.getStringExtra("THU");
String friday = intentResult.getStringExtra("FRI");
String saturday = intentResult.getStringExtra("SAT");
String sunday = intentResult.getStringExtra("SUN");
showResult.setText(monday+" , "+tuesday+" , "+wednesday+" , "+thursday+" , "+friday+", "+saturday+" , "+sunday);
}
}
boolean isChecked = myCheckBox.isChecked();
Intent i = new Intent(this, secondActivity.class);
i.putExtra("checkBoxValue", isChecked);
startActivity(i);
In your second activity onCreate
boolean isChecked = this.getIntent().getBooleanExtra("checkBoxValue", false);

Checklist log error

There is an error in my code, that I don't understand, where when a checkbox is ticked the application closes.
A brief summary of what I'm trying to do. When the check button is pressed, it tries to see what checklists have been checked and than add 1 to score if it is checked. I than to output text depending on the score received.
If there are any other mistakes I've made please point them out. Also include code example(Makes it easier to understand).
04-06 06:15:44.601 20298-20298/xyz.ashraf.whoisdelasalle E/AndroidRuntime: FATAL EXCEPTION: main
Process: xyz.ashraf.whoisdelasalle, PID: 20298
java.lang.IllegalStateException: Could not find method onCheckboxClicked(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.CheckBox with id 'concern'
at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4485)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4449)
at android.view.View.performClick(View.java:5204)
at android.widget.CompoundButton.performClick(CompoundButton.java:122)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Error code^^
package xyz.ashraf.whoisdelasalle;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
/**
* Created by Ashraf on 3/2/2016.
*/
public class check_Button extends Pop_sallian {
// Connects The variable to an xml id
TextView output = (TextView) findViewById(R.id.output);
//sets the variable to 0
int score = 0;
public void onCheckboxClicked(View v){
boolean checked = ((CheckBox) v).isChecked();
// checks what checklists have been checked
switch (v.getId()) {
case R.id.concern:
if (checked) {
score += 1;
}
break;
case R.id.faith:
if (checked) {
score += 1;
}
break;
case R.id.respect:
if (checked) {
score += 1;
}
break;
case R.id.education:
if (checked) {
score += 1;
}
break;
case R.id.community:
if (checked) {
score += 1;
}
break;
}
// adds the variables together to form a score
if (score == 0) {
output.setText("Come on! Get involved, your la sallian community needs you.");
} else if (score == 1) {
output.setText("Good start, keep going!");
} else if (score == 2) {
output.setText("Room to improve but doing good!");
} else if (score == 3) {
output.setText("Very good, others look up to you!");
} else if (score == 4) {
output.setText("Wow, you really are an inspiration");
} else if (score == 5) {
output.setText("Excellent! You're a leader in your la sallian community");
} else {
output.setText("Unknown");
}
// changes the output text based on score value
}
}
^^Code that checks the checklist and than outputs text^^
package xyz.ashraf.whoisdelasalle;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
/**
* Created by Ashraf on 1/27/2016.
*/
public class Pop_sallian extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popwindow_sallian);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int)(width*.8),(int)(height*.6));
//Creates a pop up window where the checklists are stored
Button checkButton = (Button) findViewById(R.id.check);
checkButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Pop_sallian.this, check_Button.class));
}
}); // runs the check_Button.java to check what checklists have been checked.
Button okButton = (Button) findViewById(R.id.okButton_sallian);
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});// closes the pop up window
}
}
^^ Code that contains the check button(To check if the checklists are checked and output text depending)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you a Sallian?"
android:id="#+id/textView7"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you meet the following prerequisites, if you do you may be a Sallian"
android:id="#+id/textView8"
android:layout_below="#+id/textView7"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textColor="#000000" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you concerened for the poor and Social Justice?"
android:id="#+id/concern"
android:textSize="18sp"
android:layout_below="#+id/textView8"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you have faith in the presence of God?"
android:id="#+id/faith"
android:textSize="15sp"
android:layout_below="#+id/concern"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you have Respect for all people?"
android:id="#+id/respect"
android:layout_below="#+id/faith"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:textSize="15sp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you value education?"
android:id="#+id/education"
android:textSize="15sp"
android:layout_below="#+id/respect"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:onClick="onCheckboxClicked"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you inclusive in your community?"
android:id="#+id/community"
android:layout_below="#+id/education"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="15sp"
android:checked="false"
android:onClick="onCheckboxClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:id="#+id/okButton_sallian"
android:layout_below="#+id/community"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="20dp"
android:layout_marginTop="90dp"
android:layout_marginBottom="20dp"
android:background="#FAFAFA"
android:textColor="#00E676"
android:elevation="2dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check"
android:id="#+id/check"
android:textColor="#00E676"
android:elevation="2dp"
android:background="#FAFAFA"
android:layout_alignTop="#+id/okButton_sallian"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/output"
android:textColor="#1eff00"
android:textSize="20sp"
android:layout_below="#+id/community"
android:layout_centerHorizontal="true"
android:layout_above="#+id/check"
android:textIsSelectable="false" />
</RelativeLayout>
</ScrollView>
^^ pop up xml code^^
You should set your launcher in your manifest as check_Button instead of the default, which is probably Pop_sallian.
<activity
android:name=".check_Button"
<!--stuff -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Setting an event for a button

I've asked a question similar to this. The point of this code is to check if a checklist is checked, if it is than it adds 1 to the score.
I've been told that the problem is that I haven't set an event. Please explain what I need to do to make it work, I'm new to android development and have been stuck on this for a few days. Please give a code example with your answer.
package xyz.ashraf.whoisdelasalle;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.CompoundButton.OnCheckedChangeListener;
/**
* Created by Ashraf on 3/2/2016.
*/
public class check_Button extends Pop_sallian{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popwindow_sallian);
// Connects The variable to an xml id
TextView output = (TextView) findViewById(R.id.output);
final int[] score = {0};
//sets the variable to 0
OnCheckedChangeListener checkedListener = new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch(buttonView.getId()){
case R.id.concern:
score[0]++;
break;
case R.id.faith:
score[0]++;
break;
case R.id.respect:
score[0]++;
break;
case R.id.education:
score[0]++;
break;
case R.id.community:
score[0]++;
break;
}
}
};
// adds the variables together to form a score
if(score[0] == 0){
output.setText("Come on! Get involved, your la sallian community needs you.");
} else if(score[0] == 1){
output.setText("Good start, keep going!");
} else if(score[0] == 2){
output.setText("Room to improve but doing good!");
} else if(score[0] == 3){
output.setText("Very good, others look up to you!");
} else if(score[0] == 4){
output.setText("Wow, you really are an inspiration");
} else if(score[0] == 5){
output.setText("Excellent! You're a leader in your la sallian community. Nice work!");
} else{
output.setText("Unknown");
}
// changes the output text based on score value
}
}
^^checklist code^^
package xyz.ashraf.whoisdelasalle;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.who);
Button today = (Button) findViewById(R.id.today);
Button sallian = (Button) findViewById(R.id.sallian);
Button how = (Button) findViewById(R.id.toBe);
Button moreInfo = (Button) findViewById(R.id.info);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Pop.class));
}
});
today.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Pop_today.class));
}
});
sallian.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Pop_sallian.class));
}
});
how.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Pop_how.class));
}
});
moreInfo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Pop_info.class));
}
});
}
}
^^Code where the button is and, when pressed calls on the checklist code, The Ok button is to close the pop up when pressed^^
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent">
android:elevation="8dp"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you a Sallian?"
android:id="#+id/textView7"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30sp"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you meet the following prerequisites, if you do you may be a Sallian"
android:id="#+id/textView8"
android:layout_below="#+id/textView7"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:textColor="#000000" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you concerened for the poor and Social Justice?"
android:id="#+id/concern"
android:textSize="18sp"
android:layout_below="#+id/textView8"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you have faith in the presence of God?"
android:id="#+id/faith"
android:textSize="15sp"
android:layout_below="#+id/concern"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you have Respect for all people?"
android:id="#+id/respect"
android:layout_below="#+id/faith"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp"
android:textSize="15sp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you value education?"
android:id="#+id/education"
android:textSize="15sp"
android:layout_below="#+id/respect"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="3dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you inclusive in your community?"
android:id="#+id/community"
android:layout_below="#+id/education"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="15sp"
android:checked="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:id="#+id/okButton_sallian"
android:layout_below="#+id/community"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="20dp"
android:layout_marginTop="90dp"
android:layout_marginBottom="20dp"
android:background="#FAFAFA"
android:textColor="#00E676"
android:elevation="2dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check"
android:id="#+id/check"
android:textColor="#00E676"
android:elevation="2dp"
android:background="#FAFAFA"
android:layout_alignTop="#+id/okButton_sallian"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="#+id/output"
android:textColor="#1eff00"
android:textSize="23sp"
android:layout_below="#+id/community"
android:layout_centerHorizontal="true"
android:layout_above="#+id/check" />
</RelativeLayout>
</ScrollView>
^^ xml code the code takes for^^
You are defining a checked listener, but doing nothing with it. You need to set it to your checkbox or checkboxes.
mCheckBox = (CheckBox) findViewById(R.id.concern);
mCheckBox.setOnCheckedChangedListener(checkedListener);
Just like you do on your buttons.

Button is being disabled after clicking once.I want to reuse it

In a part of my program There is a button named "imageButton_sound"in xml file "activity_exam_class_1".I want to play a sound clicking this button.First when i click it, it play sound but from the second time it doesn't work.
I initialize this xml file in"Exam_class_1.java" file .
The sequence of my program is -first I will press the"imageButton_sound" then press any other button of the same file like "imageButton_a","imageButton_b""imageButton_c"...........etc.
Then after fulfilling some condition the program will go to either "success_exam.xml" or "fail_exam.xml"
file both of which contain a button .After pressing the button it will go back to the "activity_exam_class_1",and then I will press"imageButton_sound"again and the process will be continued .
here are my code :
Exam_class_1.java:
package com.example.alphabet_school;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
public class Exam_class_1 extends Activity implements View.OnClickListener{
ImageButton im_a,im_b,im_c,im_d,im_e,im_f;
ImageButton im_success,im_fail;
ImageButton sound;
MediaPlayer joy_sound,wrong_sound,letter_sound;
int exam_sound,success=0,fail=0;
//int[] keepSound={R.raw.a,R.raw.b,R.raw.c,R.raw.d,R.raw.e,R.raw.f};
int ks=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_exam_class_1);
sound=(ImageButton) findViewById(R.id.imageButton_sound);
im_a=(ImageButton) findViewById(R.id.imageButton_a);
im_b=(ImageButton) findViewById(R.id.imageButton_b);
im_c=(ImageButton) findViewById(R.id.imageButton_c);
im_d=(ImageButton) findViewById(R.id.imageButton_d);
im_e=(ImageButton) findViewById(R.id.imageButton_e);
im_f=(ImageButton) findViewById(R.id.imageButton_f);
for(int i=0;i<6;i++){
sound.setOnClickListener(this);
im_a.setOnClickListener(this);
im_b.setOnClickListener(this);
im_c.setOnClickListener(this);
im_d.setOnClickListener(this);
im_e.setOnClickListener(this);
im_f.setOnClickListener(this);
}
// setContentView(R.layout.success_exam1);
//
// im_success = (ImageButton) findViewById(R.id.im_button_success);
// im_success.setOnClickListener(this);
//
//
// setContentView(R.layout.fail_exam1);
// im_fail=(ImageButton) findViewById(R.id.im_button_fail);
// im_fail.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.exam_class_1, menu);
return true;
}
public void onClick( View v) {
// TODO Auto-generated method stub
int opt= v.getId();
if(opt==R.id.imageButton_sound){
if(ks==0){
letter_sound = MediaPlayer.create(this,R.raw.a);
letter_sound.start();
ks++;
}
else if(ks==1){
letter_sound = MediaPlayer.create(this,R.raw.a);
letter_sound.start();
ks++;
}
else if(ks==2){
letter_sound = MediaPlayer.create(this,R.raw.a);
letter_sound.start();
ks++;
}
else if(ks==3){
letter_sound = MediaPlayer.create(this,R.raw.a);
letter_sound.start();
ks++;
}
else if(ks==4){
letter_sound = MediaPlayer.create(this,R.raw.a);
letter_sound.start();
ks++;
}
else if(ks==5){
letter_sound = MediaPlayer.create(this,R.raw.a);
letter_sound.start();
ks++;
}
}
else{
if((opt == R.id.imageButton_a && ks==1)||(opt == R.id.imageButton_b && ks==2)||
(opt == R.id.imageButton_c && ks==3)||(opt == R.id.imageButton_d && ks==4)||
(opt == R.id.imageButton_e && ks==5)||(opt == R.id.imageButton_f && ks==6)){
setContentView(R.layout.success_exam1);
joy_sound = MediaPlayer.create(this,R.raw.joy);
joy_sound.start();
}
else{
setContentView(R.layout.fail_exam1);
wrong_sound = MediaPlayer.create(this,R.raw.wrong);
wrong_sound.start();
}
}
}
public void click_success_fail(View v){
setContentView(R.layout.activity_exam_class_1);
}
}
activity_exam_class_1:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageButton
android:id="#+id/imageButton_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:contentDescription="#null"
android:src="#drawable/exam_c" />
<ImageButton
android:id="#+id/imageButton_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:contentDescription="#null"
android:src="#drawable/exam_a" />
<ImageButton
android:id="#+id/imageButton_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="#null"
android:src="#drawable/exam_d" />
<ImageButton
android:id="#+id/imageButton_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton_f"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:contentDescription="#null"
android:src="#drawable/audio_icon"
/>
<ImageButton
android:id="#+id/imageButton_f"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton_e"
android:layout_alignLeft="#+id/imageButton_d"
android:contentDescription="#null"
android:src="#drawable/exam_f" />
<ImageButton
android:id="#+id/imageButton_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton_a"
android:layout_alignLeft="#+id/imageButton_sound"
android:layout_marginLeft="44dp"
android:contentDescription="#null"
android:src="#drawable/exam_e" />
<ImageButton
android:id="#+id/imageButton_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton_c"
android:layout_alignRight="#+id/imageButton_sound"
android:layout_marginRight="47dp"
android:contentDescription="#null"
android:src="#drawable/exam_b" />
</RelativeLayout>
success_exam.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/tick1">
<ImageButton
android:id="#+id/im_button_success"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:src="#drawable/next"
android:contentDescription="#null"
android:onClick="click_success_fail"
/>
</RelativeLayout>
fail_exam.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/wrong1" >
<ImageButton
android:id="#+id/im_button_fail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:src="#drawable/try_again"
android:contentDescription="#null"
android:onClick="click_success_fail"
/>
</RelativeLayout>
slm;I think you should RE-Initialise the counter "int Ks=0;"at the end of your first part of game. try to "RE-Initialise" like this:
else{
if((opt == R.id.imageButton_a && ks==1)||(opt == R.id.imageButton_b && ks==2)||
(opt == R.id.imageButton_c && ks==3)||(opt == R.id.imageButton_d && ks==4)||
(opt == R.id.imageButton_e && ks==5)||(opt == R.id.imageButton_f && ks==6)){
Ks=0;
setContentView(R.layout.success_exam1);
joy_sound = MediaPlayer.create(this,R.raw.joy);
joy_sound.start();
}
else{ Ks=0;
setContentView(R.layout.fail_exam1);
wrong_sound = MediaPlayer.create(this,R.raw.wrong);
wrong_sound.start();
}

how to include dot operator in Edittext & Backspace for android calculator application

I'm a java beginner,I decided to made simple android calculator When i run this code Bksp doesn't work,let me help to solve this.what i'm wrong.
i also need a help how to adding a dot operator in EditText and how can i write the code to perform floating addition.
package com.tools.calculator;
import android.R.string;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
public String str ="";
Character op = 'q';
int i,num,numtemp;
EditText showResult;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showResult = (EditText) findViewById(R.id.editText1);
}
public void one(View v){
insert(1);
}
public void two(View v){
insert(2);
}
public void three(View v){
insert(3);
}
public void four(View v){
insert(4);
}
public void five(View v){
insert(5);
}
public void six(View v){
insert(6);
}
public void seven(View v){
insert(7);
}
public void eight(View v){
insert(8);
}
public void nine(View v){
insert(9);
}
public void zero(View v){
insert(0);
}
public void dot(View v)
{
/*----******** NEED HELP FOR INCLUDE THE DOT OPERATOR*****------*/
}
public void plus(View v){
perform();
op = '+';
showResult.setText("");
}
public void minus(View v){
perform();
op = '-';
showResult.setText("");
}
public void divide(View v){
perform();
op = '/';
showResult.setText("");
}
public void multiply(View v){
perform();
op = '*';
showResult.setText("");
}
public void equal(View v){
//Calculate the numbers
calculate();
}
public void Bksp(View v)
{ /* --------------------- BackSpace function------------------- */
showResult.setText(str);
String str = showResult.getText().toString();
if(str.length()>1){
str = str.substring(0, str.length() - 1);
showResult.setText(str);
}else if(str.length()<=1){
showResult.setText("");
/* --------------------- BackSpace function------------------- */
}
}
public void CLR(View v){
reset();
}
private void reset() {
/* --------------------- Reset the EditText------------------- */
str ="";
op ='q';
num = 0;
numtemp = 0;
showResult.setText("");
/* --------------------- Reset the EditText------------------- */
}
private void insert(int j) {
//Insert the values by clicking button
str = str+Integer.toString(j);
num = Integer.valueOf(str).intValue();
showResult.setText(str);
}
private void perform() {
// move the variable to temporary register
str = "";
numtemp = num;
}
private void calculate() {
// Calculation process
if(op == '+')
numtemp = numtemp+num;
else if(op == '-')
numtemp = numtemp-num;
else if(op == '/')
numtemp = numtemp/num;
else if(op == '*')
numtemp = numtemp*num;
showResult.setText(""+numtemp);
str = "";
}
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;
}
}
LAYOUT FILE
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#333333">
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button1"
android:layout_toRightOf="#+id/button1"
android:text="#string/zero"
android:onClick="zero" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_toRightOf="#+id/button2"
android:text="#string/equal"
android:onClick="equal" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button4"
android:layout_alignBottom="#+id/button4"
android:layout_alignLeft="#+id/button2"
android:text="#string/two"
android:onClick="two" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button5"
android:layout_toRightOf="#+id/button5"
android:text="#string/three"
android:onClick="three" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_centerVertical="true"
android:text="#string/four"
android:onClick="four" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button7"
android:layout_alignLeft="#+id/button5"
android:text="#string/five"
android:onClick="five"/>
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/button8"
android:text="#string/six"
android:onClick="six" />
<Button
android:id="#+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button7"
android:layout_alignLeft="#+id/button7"
android:layout_marginBottom="14dp"
android:text="#string/seven"
android:onClick="seven"/>
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button10"
android:layout_alignLeft="#+id/button8"
android:text="#string/eight"
android:onClick="eight"/>
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button11"
android:layout_toRightOf="#+id/button11"
android:text="#string/nine"
android:onClick="nine" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button7"
android:layout_marginTop="15dp"
android:layout_toLeftOf="#+id/button5"
android:text="#string/one"
android:onClick="one" />
<Button
android:id="#+id/button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button12"
android:layout_alignParentRight="true"
android:layout_marginBottom="18dp"
android:text="#string/CLR"
android:onClick="CLR"/>
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button12"
android:layout_alignBottom="#+id/button12"
android:layout_alignParentRight="true"
android:text="#string/add"
android:onClick="plus" />
<Button
android:id="#+id/button14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button9"
android:layout_alignBottom="#+id/button9"
android:layout_alignLeft="#+id/button13"
android:text="#string/sub"
android:onClick="minus" />
<Button
android:id="#+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button6"
android:layout_alignParentRight="true"
android:text="#string/mul"
android:onClick="multiply" />
<Button
android:id="#+id/button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button3"
android:layout_alignBottom="#+id/button3"
android:layout_alignLeft="#+id/button15"
android:text="#string/div"
android:onClick="divide" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button17"
android:layout_alignLeft="#+id/button10"
android:layout_alignTop="#+id/button17"
android:background="#ffffff"
android:ems="10"
android:inputType="number" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button5"
android:layout_marginLeft="18dp"
android:layout_marginTop="20dp"
android:text="#string/dot"
android:onClick="dot" />
<Button
android:id="#+id/button18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button17"
android:layout_alignLeft="#+id/button17"
android:layout_marginBottom="10dp"
android:text="#string/Bksp" />
</RelativeLayout>
XML FILE ###
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Calculator</string>
<string name="action_settings">Settings</string>
<string name="hello_world"></string>
<string name="dot">.</string>
<string name="one">1</string>
<string name="two">2</string>
<string name="three">3</string>
<string name="four">4</string>
<string name="five">5</string>
<string name="six">6</string>
<string name="seven">7</string>
<string name="eight">8</string>
<string name="nine">9</string>
<string name="zero">0</string>
<string name="add">+</string>
<string name="sub">-</string>
<string name="mul">*</string>
<string name="div">/</string>
<string name="equal">=</string>
<string name="Bksp"><--</string>
<string name="CLR">CLR</string>
</resources>
Your Bksp method is not implemented in your xml file.
Your code is horrible (one method per number?), looking your insert method you should do some edits.
private void insert(int j) {
//Insert the values by clicking button
str = str+Integer.toString(j);
num = Integer.valueOf(str).intValue();
showResult.setText(str);
}
First:
You should use Double.* methods because Integer cannot have float values.
I don't see any code which do the math so you should do the edits.
Then, to make the dot method you could just do it
private void insert() {
//Insert the values by clicking button
str = str+".0";
num = Double.valueOf(str);
showResult.setText(str);
}
It's what you should do to support dot.
Anyway, you can get remove .intValue() from Integer.valueOf(str).intValue()

Categories

Resources