Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8794581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:16:18+00:00 2026-06-13T23:16:18+00:00

I have an app that has 2 buttons: one does a calculation, the other

  • 0

I have an app that has 2 buttons: one does a calculation, the other launches a website with a browser. When the user clicks on button1, the answers should display. When the user clicks on button2, the browser will direct them to a website. The trouble is: clicking on button1 causess a “Complete action using” dialog to pop up, prompting the user to pick one of 4 things (application, process, etc.). This didn’t happen before and is quite odd. The only thing I can think of is maybe a problem with the onclicklistener and button1 doesn’t have a new intent so I don’t know how this dialog is coming up.

Here is the manifest:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.costaload"
 android:versionCode="1"
 android:versionName="1.0" >

 <uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />

 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

 </application>

 </manifest>

Here is my code:

package com.example.costaload;

import com.example.costloads.R;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Button;
import android.widget.TextView;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {
EditText mile, diesel;
Button button1, button2;
TextView tv, tv2, tv3;
private double x, y, z, costper, gallon, litres, ophours, stopdrive;
CheckBox checkBox1, checkBox2, checkBox3, checkBox4;
NumberFormat format = NumberFormat.getCurrencyInstance();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mile = (EditText) findViewById(R.id.mile);
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(button1onClickListener);
OnClickListener button2onClickListener = null;
button2.setOnClickListener(button2onClickListener);
tv = (TextView) findViewById(R.id.cost);
tv2 = (TextView) findViewById(R.id.cpm);
tv3 = (TextView) findViewById(R.id.gallons);
diesel = (EditText) findViewById(R.id.diesel);
}

private OnClickListener button1onClickListener = new OnClickListener() {
   public void onClick(final View v) {

    x = Double.parseDouble(mile.getText().toString());
    y = Double.parseDouble(diesel.getText().toString());
    if (checkBox2.isChecked()) {
        x = x * 2;
    }
    if (checkBox1.isChecked()) {
        x = x * 0.62137;
    }
    ophours = 0;
    ophours = (x / 55) + 2;
    if (ophours >= 11) {
        stopdrive = (ophours / 10) - 1;
        if (stopdrive > 1) { // This block isn't closed.
            ophours = ophours + (stopdrive * 10);
        }
        gallon = x / 5.5;
        if (checkBox4.isChecked()) {
            gallon = gallon + (ophours * 1.1);
        }
        if (checkBox3.isChecked()) {
            litres = gallon * 3.785;
            tv3.setText(new DecimalFormat("####.##").format(litres)
                    + "L");
        }
        z = (gallon * y) + (x * 0.655);
        costper = z / x;
        tv.setText(format.format(z));
        tv2.setText(format.format(costper) + "/mile");
        tv3.setText(new DecimalFormat("####.##").format(gallon)
                + "gal.");
    }
    ;
};

private OnClickListener button2OnClickListener = new OnClickListener() {
    public void onClick(final View v) {

        Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Url.parse("http://www.ratenroll.com"));
        startActivity(browserIntent);
    }
  };
 };
};

Here is the activity xml:

<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" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="# of miles"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="40dp"
    android:text="Price of diesel"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/diesel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView2"
    android:layout_alignBottom="@+id/textView2"
    android:layout_alignLeft="@+id/mile"
    android:layout_alignParentRight="true"
    android:ems="10"
    android:inputType="numberDecimal" />

<EditText
    android:id="@+id/mile"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/checkBox3"
    android:ems="10"
    android:inputType="numberDecimal" >

    <requestFocus />
</EditText>

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text="Visit www.ratenroll.com" />

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/diesel"
    android:layout_marginTop="14dp"
    android:text="Kilometres (not miles)" />

<CheckBox
    android:id="@+id/checkBox2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/checkBox1"
    android:layout_alignBottom="@+id/checkBox1"
    android:layout_alignParentRight="true"
    android:text="Round trip" />

<CheckBox
    android:id="@+id/checkBox3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/checkBox1"
    android:text="Litres (not gallons)" />

<CheckBox
    android:id="@+id/checkBox4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/checkBox3"
    android:layout_alignBottom="@+id/checkBox3"
    android:layout_alignParentRight="true"
    android:text="Reefer load" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/checkBox3"
    android:layout_marginTop="50dp"
    android:layout_toRightOf="@+id/textView2"
    android:text="Compute" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button1"
    android:layout_marginTop="26dp"
    android:text="Total Cost"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView3"
    android:text="Cost per mile"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/cost"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView4"
    android:layout_alignParentRight="true"
    android:text=" "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/cpm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView4"
    android:layout_alignBottom="@+id/textView4"
    android:layout_alignParentRight="true"
    android:text="   "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/textView4"
    android:layout_below="@+id/textView4"
    android:text="Fuel required"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/gallons"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView5"
    android:layout_alignBottom="@+id/textView5"
    android:layout_alignParentRight="true"
    android:text="   "
    android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Thank you for looking.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:16:18+00:00Added an answer on June 13, 2026 at 11:16 pm

    Your method of adding the same onClickListener to two buttons and using a switch statement to distinguish them is prone to errors.

    package com.example.costaload;
    
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    
    import android.net.Uri;
    import android.os.Bundle;
    import android.app.Activity;
    import android.content.Intent;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.Button;
    import android.widget.TextView;
    import android.view.View;
    import android.view.View.OnClickListener;
    
    public class MainActivity extends Activity {
        EditText mile, diesel;
        Button button1, button2;
        TextView tv, tv2, tv3;
        private double x, y, z, costper, gallon, litres, ophours, stopdrive;
        CheckBox checkBox1, checkBox2, checkBox3, checkBox4;
        NumberFormat format = NumberFormat.getCurrencyInstance();
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mile = (EditText) findViewById(R.id.mile);
            checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
            checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
            checkBox3 = (CheckBox) findViewById(R.id.checkBox3);
            checkBox4 = (CheckBox) findViewById(R.id.checkBox4);
            button1 = (Button) findViewById(R.id.button1);
            button2 = (Button) findViewById(R.id.button2);
            button1.setOnClickListener(button1onClickListener);
            button2.setOnClickListener(button2OnClickListener);
            tv = (TextView) findViewById(R.id.cost);
            tv2 = (TextView) findViewById(R.id.cpm);
            tv3 = (TextView) findViewById(R.id.gallons);
            diesel = (EditText) findViewById(R.id.diesel);
        }
    
        private OnClickListener button1onClickListener = new OnClickListener() {
            public void onClick(final View v) {
    
                x = Double.parseDouble(mile.getText().toString());
                y = Double.parseDouble(diesel.getText().toString());
                if (checkBox2.isChecked()) {
                    x = x * 2;
                }
    
                if (checkBox1.isChecked()) {
                    x = x * 0.62137;
                }
    
                ophours = 0;
                ophours = (x / 55) + 2;
    
                if (ophours >= 11) {
                    stopdrive = (ophours / 10) - 1;
                }
                if (stopdrive > 1) {
                    ophours = ophours + (stopdrive * 10);
                }
    
                gallon = x / 5.5;
    
                if (checkBox4.isChecked()) {
                    gallon = gallon + (ophours * 1.1);
                }
    
                if (checkBox3.isChecked()) {
                    litres = gallon * 3.785;
                    tv3.setText(new DecimalFormat("####.##").format(litres) + "L");
                }
    
                z = (gallon * y) + (x * 0.655);
                costper = z / x;
                tv.setText(format.format(z));
                tv2.setText(format.format(costper) + "/mile");
                tv3.setText(new DecimalFormat("####.##").format(gallon) + "gal.");
            }
    
        };
    
        private OnClickListener button2OnClickListener = new OnClickListener() {
            public void onClick(final View v) {
    
                Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.ratenroll.com"));
                startActivity(browserIntent);
            }
        };
    };
    

    I didn’t change your xml file.

    Good Luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have an app that has listings - think classified ads - and each listing
I have an app that has different names for different languages. How do I
I have an app that has a centre view with two views off to
I have an app that has a tabbar at the bottom. When I select
I have an app that has a TableView, NavigationView and TabBar running together. There
I have an app that has a list of items. My customer prefers to
i have an app that has a few checkboxes in the settings and then
I have an app that has a mapview, and it shows 20 pins (from
I have an app that has some configuration settings stored in SharedPreference. Now I
I have an app that has a bunch of Core Data that it needs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.