有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在安卓中检测到java应用程序故障

我是新安卓开发者。所以我看了视频,制作了这个小提示计算器。但当我运行我的应用程序时,它会关闭,并给出错误消息。如果应用程序失败,请重试。 我真的很想知道我在这些代码中哪里出错了

我添加了两个文件:

CrazyTipCalc。java

package com.ashish.crazytipcalc;

import 安卓.os.Bundle;
import 安卓.os.SystemClock;
import 安卓.app.Activity;
import 安卓.text.Editable;
import 安卓.text.TextWatcher;
import 安卓.view.Menu;
import 安卓.view.View;
import 安卓.view.View.OnClickListener;
import 安卓.widget.AdapterView;
import 安卓.widget.AdapterView.OnItemSelectedListener;
import 安卓.widget.Button;
import 安卓.widget.CheckBox;
import 安卓.widget.Chronometer;
import 安卓.widget.CompoundButton;
import 安卓.widget.EditText;
import 安卓.widget.RadioButton;
import 安卓.widget.RadioGroup;
import 安卓.widget.RadioGroup.OnCheckedChangeListener;
import 安卓.widget.SeekBar;
import 安卓.widget.SeekBar.OnSeekBarChangeListener;
import 安卓.widget.Spinner;
import 安卓.widget.TextView;

public class CrazyTipCalc extends Activity {

    private static final String TOTAL_BILL = "TOTAL_BILL";
    private static final String CURRENT_TIP = "CURRENT_TIP";
    private static final String BILL_WITHOUT_TIP = "BILL_WITHOUT_TIP";

    private double billBeforeTip, tipAmount, finalBill;

    EditText billBeforeTipET, tipAmountET,finalBillET;

    SeekBar tipSeekBar;

    private int[] checkListValue = new int[12];

    CheckBox friendlyCB, spacialsCB, opinionCB;

    RadioGroup radioGroup1;

    RadioButton badRadio, goodRadio, bestRadio;

    Spinner problemSpinner;

    Button startButton, pauseButton, resetButton;

    Chronometer timeWaitChronometer;

    long secondsYouWaited = 0;

    TextView timeWatingTextView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crazy_tip_calc);

        if(savedInstanceState == null){
            billBeforeTip = 0.0;
            tipAmount = .15;
            finalBill = 0.0;
        }else {
            billBeforeTip = savedInstanceState.getDouble(BILL_WITHOUT_TIP);
            tipAmount = savedInstanceState.getDouble(CURRENT_TIP);
            finalBill = savedInstanceState.getDouble(TOTAL_BILL);
        }

        billBeforeTipET = (EditText) findViewById(R.id.billEditText);
        tipAmountET = (EditText) findViewById(R.id.tipEditText);
        finalBillET = (EditText) findViewById(R.id.finalEditText);

        tipSeekBar = (SeekBar) findViewById(R.id.changeTipSeekBar);
        tipSeekBar.setOnSeekBarChangeListener(tipSeekBarListener);

        billBeforeTipET.addTextChangedListener(billBeforeTipListener);

        friendlyCB = (CheckBox) findViewById(R.id.friendlyCheckBox);
        spacialsCB = (CheckBox) findViewById(R.id.spacialCheckBox);
        opinionCB = (CheckBox) findViewById(R.id.opinionCheckBox);

        setUpIntroCheckBoxes();

        radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
        badRadio = (RadioButton) findViewById(R.id.badRadio);
        goodRadio = (RadioButton) findViewById(R.id.goodRadio);
        bestRadio = (RadioButton) findViewById(R.id.bestRadio);

        addChangeListenerToRadio();

        problemSpinner = (Spinner) findViewById(R.id.problemSpinner);
        addItemSelectedListeners();

        startButton = (Button) findViewById(R.id.startButtonTextView);
        pauseButton = (Button) findViewById(R.id.pauseButton);
        resetButton = (Button) findViewById(R.id.resetButton);

        setButtonOnClickListener();

        timeWaitChronometer = (Chronometer) findViewById(R.id.timeWaitChronometer);
        timeWatingTextView = (Chronometer) findViewById(R.id.timeWaitTextView);

    }

    private TextWatcher billBeforeTipListener = new TextWatcher () {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            try{
                billBeforeTip = Double.parseDouble(s.toString());       
            }
            catch(NumberFormatException e){
                updateTipAndFinalBill();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
             //TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
             //TODO Auto-generated method stub

        }
    };

    private void updateTipAndFinalBill(){
        double tipAmount = Double.parseDouble(tipAmountET.getText().toString());
        double finalBill = billBeforeTip + (billBeforeTip * tipAmount);
        finalBillET.setText(String.format("%.02f", finalBill));
    }

    protected void onSaveInstanceState(Bundle outState){
        super.onSaveInstanceState(outState);
        outState.putDouble(TOTAL_BILL, finalBill);
        outState.putDouble(CURRENT_TIP, tipAmount);
        outState.putDouble(BILL_WITHOUT_TIP, billBeforeTip);
    }

    private OnSeekBarChangeListener tipSeekBarListener = new OnSeekBarChangeListener(){

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {
            tipAmount = (tipSeekBar.getProgress()) * .01;
            tipAmountET.setText(String.format("%.02f", tipAmount));
            updateTipAndFinalBill();

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
             //TODO Auto-generated method stub

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
             //TODO Auto-generated method stub

        }

    };

    private void setUpIntroCheckBoxes(){
        friendlyCB.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                        checkListValue[0] = (friendlyCB.isChecked())?4:0;
                        setTipFromWaitressChecklist();
                        updateTipAndFinalBill();    
            }           
        });

        opinionCB.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                        checkListValue[2] = (opinionCB.isChecked())?2:0;
                        setTipFromWaitressChecklist();
                        updateTipAndFinalBill();    
            }           
        });

        spacialsCB.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                        checkListValue[1] = (spacialsCB.isChecked())?1:0;
                        setTipFromWaitressChecklist();
                        updateTipAndFinalBill();    
            }           
        });     
    }

    private void setTipFromWaitressChecklist(){
        int ChecklistTotal = 0;
        for(int item : checkListValue){
            ChecklistTotal += item;
        }
        tipAmountET.setText(String.format("%.02f", ChecklistTotal * 0.1));
    }

    private void addChangeListenerToRadio(){
        radioGroup1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

                checkListValue[2] = (badRadio.isChecked())?-1:0;
                checkListValue[3] = (goodRadio.isChecked())?2:0;
                checkListValue[4] = (bestRadio.isChecked())?4:0; 
                setTipFromWaitressChecklist();
                updateTipAndFinalBill();
            }
        });
    }

    private void addItemSelectedListeners(){
        problemSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                checkListValue[6] = (problemSpinner.getSelectedItem()).equals("bad")?-1:0;
                checkListValue[7] = (problemSpinner.getSelectedItem()).equals("good")?3:0;
                checkListValue[8] = (problemSpinner.getSelectedItem()).equals("best")?6:0; 
                setTipFromWaitressChecklist();
                updateTipAndFinalBill();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub              
            }           
        });
    }

    private void setButtonOnClickListener(){
        startButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                int stoppedMilliseconds = 0;
                String chronoText = timeWaitChronometer.getText().toString();
                String array[]  = chronoText.split(":");

                if(array.length == 2){
                    stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 1000 +
                            Integer.parseInt(array[1]) * 1000;
                }else if(array.length == 3){
                    stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 60 * 1000 +
                            Integer.parseInt(array[1]) * 60 * 1000 + 
                            Integer.parseInt(array[2]) * 1000;
                }
                timeWaitChronometer.setBase(SystemClock.elapsedRealtime() - stoppedMilliseconds);
                secondsYouWaited = Long.parseLong(array[1]);
                updateTipBasedOnTimeWaited(secondsYouWaited);
                timeWaitChronometer.start();
            }
        });

        pauseButton.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                timeWaitChronometer.stop();

            }

        });

        resetButton.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                timeWaitChronometer.setBase(SystemClock.elapsedRealtime());
                secondsYouWaited = 0;

            }
    });
}

    private void updateTipBasedOnTimeWaited(long secondsYouWaited) {
        checkListValue[9] = (secondsYouWaited > 10)?-2:2;
        setTipFromWaitressChecklist();
        updateTipAndFinalBill();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
         //Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.crazy_tip_calc, menu);
        return true;
    }

}

活动_疯狂_提示_Calc.XML

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:paddingBottom="@dimen/activity_vertical_margin"
    安卓:paddingLeft="@dimen/activity_horizontal_margin"
    安卓:paddingRight="@dimen/activity_horizontal_margin"
    安卓:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".CrazyTipCalc" >

    <TextView
        安卓:id="@+id/billTextView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentLeft="true"
        安卓:layout_alignParentTop="true"
        安卓:layout_marginLeft="14dp"
        安卓:layout_marginTop="15dp"
        安卓:text="@string/bill_text_view" />

    <EditText
        安卓:id="@+id/billEditText"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBaseline="@+id/billTextView"
        安卓:layout_alignBottom="@+id/billTextView"
        安卓:layout_marginLeft="14dp"
        安卓:layout_toRightOf="@+id/billTextView"
        安卓:ems="5"
        安卓:inputType="numberDecimal"
        安卓:text="@string/bill_edit_text" >

        <requestFocus />
    </EditText>

    <TextView
        安卓:id="@+id/tipTextView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBottom="@+id/billTextView"
        安卓:layout_marginLeft="15dp"
        安卓:layout_toRightOf="@+id/billEditText"
        安卓:text="@string/tip_text_view" />

    <EditText
        安卓:id="@+id/tipEditText"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBaseline="@+id/tipTextView"
        安卓:layout_alignBottom="@+id/tipTextView"
        安卓:layout_marginLeft="17dp"
        安卓:layout_toRightOf="@+id/tipTextView"
        安卓:ems="4"
        安卓:inputType="numberDecimal"
        安卓:text="@string/tip_edit_text" />

    <SeekBar
        安卓:id="@+id/changeTipSeekBar"
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"
        安卓:layout_alignTop="@+id/changeTipTextView"
        安卓:layout_marginLeft="27dp"
        安卓:layout_toRightOf="@+id/changeTipTextView"
        安卓:progress="15" />

    <TextView
        安卓:id="@+id/finalTextView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_below="@+id/changeTipSeekBar"
        安卓:layout_marginTop="14dp"
        安卓:layout_toLeftOf="@+id/changeTipSeekBar"
        安卓:text="@string/final_text_view" />

    <EditText
        安卓:id="@+id/finalEditText"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBaseline="@+id/finalTextView"
        安卓:layout_alignBottom="@+id/finalTextView"
        安卓:layout_alignRight="@+id/changeTipSeekBar"
        安卓:ems="10"
        安卓:inputType="numberDecimal"
        安卓:text="@string/final_edit_text" />

    <TextView
        安卓:id="@+id/changeTipTextView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignLeft="@+id/billTextView"
        安卓:layout_below="@+id/billEditText"
        安卓:layout_marginTop="30dp"
        安卓:text="@string/change_tip_text_view" />

    <TextView
        安卓:id="@+id/introTextView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignLeft="@+id/finalTextView"
        安卓:layout_below="@+id/finalEditText"
        安卓:layout_marginTop="15dp"
        安卓:text="@string/intro_text_view" />

    <CheckBox
        安卓:id="@+id/opinionCheckBox"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBaseline="@+id/spacialCheckBox"
        安卓:layout_alignBottom="@+id/spacialCheckBox"
        安卓:layout_alignParentRight="true"
        安卓:text="@string/opinion_text_view" />

    <CheckBox
        安卓:id="@+id/friendlyCheckBox"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignRight="@+id/introTextView"
        安卓:layout_below="@+id/introTextView"
        安卓:text="@string/friendly_text_view" />

    <CheckBox
        安卓:id="@+id/spacialCheckBox"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBaseline="@+id/friendlyCheckBox"
        安卓:layout_alignBottom="@+id/friendlyCheckBox"
        安卓:layout_centerHorizontal="true"
        安卓:text="@string/spacial_text_view" />

    <TextView
        安卓:id="@+id/availTextView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignLeft="@+id/introTextView"
        安卓:layout_below="@+id/friendlyCheckBox"
        安卓:text="@string/available_text_view" />

    <RadioGroup
        安卓:id="@+id/radioGroup1"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignLeft="@+id/friendlyCheckBox"
        安卓:layout_below="@+id/availTextView"
        安卓:orientation="horizontal" >

        <RadioButton
            安卓:id="@+id/badRadio"
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:checked="true"
            安卓:text="@string/bad_radiobutton" />
    </RadioGroup>

    <RadioButton
        安卓:id="@+id/goodRadio"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_below="@+id/availTextView"
        安卓:layout_toRightOf="@+id/friendlyCheckBox"
        安卓:text="@string/good_radiobutton" />

    <Spinner
        安卓:id="@+id/problemSpinner"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentRight="true"
        安卓:layout_below="@+id/bestRadio"
        安卓:layout_marginTop="27dp"
        安卓:entries="@array/problem_solving" />

    <TextView
        安卓:id="@+id/timeWaitTextView"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignRight="@+id/goodRadio"
        安卓:layout_below="@+id/problemSpinner"
        安卓:text="@string/time_waiting_text_view" />

    <Chronometer
        安卓:id="@+id/timeWaitChronometer"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignLeft="@+id/bestRadio"
        安卓:layout_alignTop="@+id/timeWaitTextView"
        安卓:layout_toLeftOf="@+id/opinionCheckBox"
        安卓:text="@string/chronometer_view" />

    <Button
        安卓:id="@+id/startButtonTextView"
        style="?安卓:attr/buttonStyleSmall"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignRight="@+id/availTextView"
        安卓:layout_below="@+id/timeWaitChronometer"
        安卓:layout_marginTop="22dp"
        安卓:text="@string/start_button" />

    <Button
        安卓:id="@+id/resetButton"
        style="?安卓:attr/buttonStyleSmall"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBaseline="@+id/pauseButton"
        安卓:layout_alignBottom="@+id/pauseButton"
        安卓:layout_toRightOf="@+id/spacialCheckBox"
        安卓:text="@string/reset_button" />

    <Button
        安卓:id="@+id/pauseButton"
        style="?安卓:attr/buttonStyleSmall"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignBaseline="@+id/startButtonTextView"
        安卓:layout_alignBottom="@+id/startButtonTextView"
        安卓:layout_alignLeft="@+id/spacialCheckBox"
        安卓:text="@string/pause_button" />

    <RadioButton
        安卓:id="@+id/bestRadio"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignRight="@+id/resetButton"
        安卓:layout_below="@+id/availTextView"
        安卓:text="@string/best_radiobutton" />

</RelativeLayout>

LOGCAT错误

08-03 23:21:33.670: E/ActivityThread(7873): Failed to find provider info for settings
08-03 23:21:39.680: E/ThrottleService(7909): Could not open GPS configuration file             /etc/gps.conf
08-03 23:21:40.530: E/Vold(485): ASEC com.whatsapp.wallpaper-1 already mounted
08-03 23:21:52.380: E/ActivityThread(8387): Failed to find provider info for com.sec.badge
08-03 23:21:55.840: E/ActivityThread(8289): Failed to find provider info for icc
08-03 23:22:45.040: E/PackageManager(7909): Package com.google.安卓.gms has no     signatures that match those in shared user com.google.uid.shared; ignoring!
08-03 23:25:16.730: E/ThrottleService(8588): Could not open GPS configuration file /etc/gps.conf
08-03 23:25:17.180: E/Vold(485): ASEC com.whatsapp.wallpaper-1 already mounted
08-03 23:25:43.060: E/PGA(8588): PgaSocketWriteAllHdipc: hd_ipc_send() failed
08-03 23:25:43.380: E/ActivityManager(8588): Exception in bstSendTopActivityInfo while sending HttpPost: Connection to http://10.0.2.2:2862 refused
08-03 23:25:43.510: E/ActivityThread(8988): Failed to find provider info for icc
08-03 23:25:43.890: E/ActivityManager(8588): Exception in bstSendTopActivityInfo while sending HttpPost: Connection to http://10.0.2.2:2862 refused
08-03 23:25:44.320: E/PGA(8588): PgaSocketWriteAllHdipc: hd_ipc_send() failed

共 (1) 个答案

  1. # 1 楼答案

    我没有写一些方法。我已经做到了,效果非常好

    public class CrazyTipCalc extends Activity {
    
    private static final String TOTAL_BILL = "TOTAL_BILL";
    private static final String CURRENT_TIP = "CURRENT_TIP";
    private static final String BILL_WITHOUT_TIP = "BILL_WITHOUT_TIP";
    
    private double billBeforeTip; // Users bill before tip
    private double tipAmount; // Tip amount
    private double finalBill; // Bill plus Tip
    
    EditText billBeforeTipET;
    EditText tipAmountET;
    EditText finalBillET;
    
    private int[] checklistValues = new int[12]; 
    
    CheckBox friendlyCheckBox;
    CheckBox specialsCheckBox;
    CheckBox opinionCheckBox;
    
    RadioGroup availableRadioGroup;
    RadioButton availableBadRadio;
    RadioButton availableOKRadio;
    RadioButton availableGoodRadio;
    
    Spinner problemsSpinner;
    
    Button startChronometerButton;
    Button pauseChronometerButton;
    Button resetChronometerButton;
    
    Chronometer timeWaitingChronometer;
    
    long secondsYouWaited = 0;
    
    TextView timeWaitingTextView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_crazy_tip_calc); // Inflate the GUI
    
        if(savedInstanceState == null){
    
            // Just started
    
            billBeforeTip = 0.0;
            tipAmount = .15; 
            finalBill = 0.0; 
    
        } else {
    
            // App is being restored
    
            billBeforeTip = savedInstanceState.getDouble(BILL_WITHOUT_TIP);
            tipAmount = savedInstanceState.getDouble(CURRENT_TIP); 
            finalBill = savedInstanceState.getDouble(TOTAL_BILL); 
    
        }
    
        billBeforeTipET = (EditText) findViewById(R.id.billEditText); // Users bill before tip
        tipAmountET = (EditText) findViewById(R.id.tipEditText); // Tip amount
        finalBillET = (EditText) findViewById(R.id.finalBillEditText); // Bill plus tip
    
        tipSeekBar = (SeekBar) findViewById(R.id.changeTipSeekBar);
    
        tipSeekBar.setOnSeekBarChangeListener(tipSeekBarListener);
    
        billBeforeTipET.addTextChangedListener(billBeforeTipListener);
    
        friendlyCheckBox = (CheckBox) findViewById(R.id.friendlyCheckBox);
        specialsCheckBox = (CheckBox) findViewById(R.id.specialsCheckBox);
        opinionCheckBox = (CheckBox) findViewById(R.id.opinionCheckBox);
    
        setUpIntroCheckBoxes();
        availableBadRadio = (RadioButton) findViewById(R.id.availableBadRadio);
        availableOKRadio = (RadioButton) findViewById(R.id.availableOKRadio);
        availableGoodRadio = (RadioButton) findViewById(R.id.availableGoodRadio);
        availableRadioGroup = (RadioGroup) findViewById(R.id.availableRadioGroup);
    
        addChangeListenerToRadios();
        problemsSpinner = (Spinner) findViewById(R.id.problemsSpinner);
    
        problemsSpinner.setPrompt("Problem Solving");
    
        addItemSelectedListenerToSpinner();
    
        startChronometerButton = (Button) findViewById(R.id.startChronometerButton);
        pauseChronometerButton = (Button) findViewById(R.id.pauseChronometerButton);
        resetChronometerButton = (Button) findViewById(R.id.resetChronometerButton);
    
        setButtonOnClickListeners();
    
        timeWaitingChronometer = (Chronometer) findViewById(R.id.timeWaitingChronometer);
    
        timeWaitingTextView = (TextView) findViewById(R.id.timeWaitingTextView);
    
    }   
    
    private TextWatcher billBeforeTipListener = new TextWatcher(){
    
        @Override
        public void afterTextChanged(Editable arg0) {
        }
    
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
    
        }
    
        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
    
            try{
    
                billBeforeTip = Double.parseDouble(arg0.toString());
    
            }
    
            catch(NumberFormatException e){
    
                billBeforeTip = 0.0;
    
            }
    
            updateTipAndFinalBill();
    
        }
    
    };
    private void updateTipAndFinalBill(){
    
        double tipAmount = Double.parseDouble(tipAmountET.getText().toString());
    
        double finalBill = billBeforeTip + (billBeforeTip * tipAmount);
    
        finalBillET.setText(String.format("%.02f", finalBill));
    
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState){
    
        super.onSaveInstanceState(outState);
    
        outState.putDouble(TOTAL_BILL, finalBill);
        outState.putDouble(CURRENT_TIP, tipAmount);
        outState.putDouble(BILL_WITHOUT_TIP, billBeforeTip);
    
    }
    
    private SeekBar tipSeekBar;
    
    private OnSeekBarChangeListener tipSeekBarListener = new OnSeekBarChangeListener(){
    
        @Override
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
    
    
            tipAmount = (tipSeekBar.getProgress()) * .01;
    
            tipAmountET.setText(String.format("%.02f", tipAmount));
    
            updateTipAndFinalBill();
    
        }
    
        @Override
        public void onStartTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void onStopTrackingTouch(SeekBar arg0) {
            // TODO Auto-generated method stub
    
        }
    
    };
    
    
    private void setUpIntroCheckBoxes(){
    
        friendlyCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
    
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
    
                checklistValues[0] = (friendlyCheckBox.isChecked())?4:0;
    
                setTipFromWaitressChecklist(); 
    
                updateTipAndFinalBill();
    
            }
    
        });
    
        specialsCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
    
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
    
                checklistValues[1] = (specialsCheckBox.isChecked())?1:0;
    
                setTipFromWaitressChecklist();      
                updateTipAndFinalBill();        
            }
    
        });     
    
        opinionCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
    
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
    
                checklistValues[2] = (opinionCheckBox.isChecked())?2:0;
    
                setTipFromWaitressChecklist();      
                updateTipAndFinalBill();
    
            }       
        });             
    }
    private void setTipFromWaitressChecklist(){
    
        int checklistTotal = 0;
    
        for(int item : checklistValues){
    
            checklistTotal += item;
    
        }
    
        tipAmountET.setText(String.format("%.02f", checklistTotal * .01));
    }
    
    private void addChangeListenerToRadios(){
    
        availableRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() 
        {
    
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                checklistValues[3] = (availableBadRadio.isChecked())?-1:0;
                checklistValues[4] = (availableOKRadio.isChecked())?2:0;
                checklistValues[5] = (availableGoodRadio.isChecked())?4:0;              
                setTipFromWaitressChecklist(); 
                updateTipAndFinalBill();                
            }
        });
    
    }
    
    private void addItemSelectedListenerToSpinner(){        
        problemsSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
    
                checklistValues[6] = (String.valueOf(problemsSpinner.getSelectedItem()).equals("Bad"))?-1:0;
                checklistValues[7] = (String.valueOf(problemsSpinner.getSelectedItem()).equals("OK"))?3:0;
                checklistValues[8] = (String.valueOf(problemsSpinner.getSelectedItem()).equals("Good"))?6:0;
    
                setTipFromWaitressChecklist();                      
                updateTipAndFinalBill();            
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
    
            }           
        });     
    }
    
    private void setButtonOnClickListeners(){   
        startChronometerButton.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                int stoppedMilliseconds = 0;
    
                String chronoText = timeWaitingChronometer.getText().toString();
                String array[] = chronoText.split(":");
                if (array.length == 2) {
    
                  stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 1000
                        + Integer.parseInt(array[1]) * 1000;
                } else if (array.length == 3) {
    
                  stoppedMilliseconds = Integer.parseInt(array[0]) * 60 * 60 * 1000 
                        + Integer.parseInt(array[1]) * 60 * 1000
                        + Integer.parseInt(array[2]) * 1000;
                }
    
                timeWaitingChronometer.setBase(SystemClock.elapsedRealtime() - stoppedMilliseconds);
    
                secondsYouWaited = Long.parseLong(array[1]);
    
                updateTipBasedOnTimeWaited(secondsYouWaited);
                timeWaitingChronometer.start();             
            }                       
        });     
        pauseChronometerButton.setOnClickListener(new OnClickListener(){
    
            @Override
            public void onClick(View arg0) {
                timeWaitingChronometer.stop();              
            }                       
        });
    
        resetChronometerButton.setOnClickListener(new OnClickListener(){
    
            @Override
            public void onClick(View arg0) {
    
                timeWaitingChronometer.setBase(SystemClock.elapsedRealtime());
                secondsYouWaited = 0;
            }
        });
    }
    
    private void updateTipBasedOnTimeWaited(long secondsYouWaited){
    
        checklistValues[9] = (secondsYouWaited > 10)?-2:2;
    
        setTipFromWaitressChecklist(); 
    
        updateTipAndFinalBill();    
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.crazy_tip_calc, menu);
        return true;
    }