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

  • SEARCH
  • Home
  • 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 8758657
In Process

The Archive Base Latest Questions

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

Good Day, I am new to android and using Eclipse 3.7.2. I have been

  • 0

Good Day,

I am new to android and using Eclipse 3.7.2. I have been following examples on the net (the so-called “add two numbers” examples but, after discovering that AbsoluteLayout is deprecated, I am using RelativeLayout and basically going from scratch. The app basically is supposed to take two numbers (how far a guy went and how much he is paid per mile) and pop out total pay.

The app compiles fine and starts up in the emulator. I get excited! Pop in 2 numbers and hit the button. Nothing. I look and see that there’s no errors happening.

Am I missing something with my button listener? Here is the Java code I’ve put in (updated 5:27pm 10.31.2012):

package com.example.wing_it;

import android.os.Bundle;
import android.app.Activity;
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 {
EditText mile,driver;
Button button1;
TextView tv;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mile= (EditText) findViewById(R.id.mile);
    button1 = (Button) findViewById(R.id.button1);
    tv = (TextView) findViewById(R.id.pay);
    driver= (EditText) findViewById(R.id.driver);
    button1.setOnClickListener((OnClickListener) this);
    }


public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
class clicker implements Button.OnClickListener
{
public void onClick(View v) {
    // TODO Auto-generated method stub
    {
        String a,b;
        Integer vis;
        a = mile.getText().toString();
        b = driver.getText().toString();
        vis = Integer.parseInt(a)*Integer.parseInt(b);
        tv.setText(vis.toString());
        }
    }
}       
}

The XML code is as such:

<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="@string/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="@string/paypermile"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView2"
    android:layout_marginLeft="52dp"
    android:layout_marginTop="62dp"
    android:layout_toRightOf="@+id/textView2"
    android:text="@string/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="46dp"
    android:text="@string/pay"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<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/button1"
    android:ems="10"
    android:inputType="numberDecimal" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/driver"
    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" />

<TextView
    android:id="@+id/pay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/textView3"
    android:layout_alignBottom="@+id/textView3"
    android:layout_alignParentRight="true"
    android:text="@string/totalpay"
    android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Here is the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wing_it"
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>

I have the value of the result textview set to nothing (just a blank) in the strings.xml. It was set to ‘0’ and I removed that to see if it would make a difference. Still, nothing.

Is there something I am overlooking here? 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-13T14:36:17+00:00Added an answer on June 13, 2026 at 2:36 pm
        public class MainActivity extends Activity implements OnClickListener {
    
        public void onCreate() {
         button1 = (Button) findViewById(R.id.button1);
         button1.setOnClickListener(this);
        }
    
        public void onClick(View view) {
           // code here
        }
    

    it’s hard to read your code, but this should work (sorry if i have spelling errors, i cannot cut/paste from my code (on another machine)

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

Sidebar

Related Questions

Good day (and happy New Year), I'm a beginner VB.Net programmer using VS 2008.
Good day! I'm new in using Java DB (Derby). I want to embed it
Good day, I have a local csv file with values that change daily called
Good Day All, I’m new to programming. I’m using Visual Studio 2010. I’m taking
Good Day All, I’m new to programming. I’m using Visual Studio 2010. I’m taking
Good day! I'm quite new to scala, so during development the following question was
Good day to all. I have a question, i'm using wpf and i cant
Good day everyone. I have a question about making and using derived classes of
Following is the code which i am using to add events in my android
Good day guys. I have the following struct and class, template <class T> struct

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.