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 9051053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:48:40+00:00 2026-06-16T12:48:40+00:00

I’m creating a simple android app, which has and editText field and a textView

  • 0

I’m creating a simple android app, which has and editText field and a textView field, the values within these fields are only numeric.

I have created a button which on selecting, I would like the value of the edit text and text view to be added together, I would then like the editText to change to a value of ‘0’ and teh total to be displayed in the textView.

For example if the editText has a value of 10 and the textView has a value of 20 on pressing the button the total of 30 is displayed in the textView and the value of the editText displays 0.

Here is my code so far, when I press the button at the moment the app crashes so I am not confident that I have coded correctly. I am new to java. Any help would be greatly appreciated.

public class durood extends Activity{

TextView txtCount;
TextView totalCount;
EditText enteramount;
Button btnCount;
Button addtotal1;
Button addtotal2;
Button cleartotal;
static int count=0;
double x=0;
double y=0;
double z=0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// The activity is being created.
setContentView(R.layout.durood);

enteramount = (EditText)findViewById(R.id.enteramount);
totalCount = (TextView)findViewById(R.id.totalCount);
addtotal1=(Button)findViewById(R.id.addtototal1);
addtotal2=(Button)findViewById(R.id.addtototal2);


//add to total 1
addtotal1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

x=Double.parseDouble(enteramount.getText().toString());
y=Double.parseDouble(totalCount.getText().toString());
z=x+y;
totalCount.setText(Double.toString(z));
}


});

LogCat

12-30 23:52:11.098: W/Trace(615): Unexpected value from nativeGetEnabledTags: 0
12-30 23:52:11.129: E/ActivityThread(615): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d332e8 that was originally bound here
12-30 23:52:11.129: E/ActivityThread(615): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d332e8 that was originally bound here
12-30 23:52:11.129: E/ActivityThread(615):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-30 23:52:11.129: E/ActivityThread(615):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-30 23:52:11.129: E/ActivityThread(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-30 23:52:11.129: E/ActivityThread(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-30 23:52:11.129: E/ActivityThread(615):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-30 23:52:11.129: E/ActivityThread(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-30 23:52:11.129: E/ActivityThread(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-30 23:52:11.129: E/ActivityThread(615):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
12-30 23:52:11.129: E/ActivityThread(615):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
12-30 23:52:11.129: E/ActivityThread(615):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
12-30 23:52:11.129: E/ActivityThread(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-30 23:52:11.129: E/ActivityThread(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-30 23:52:11.129: E/ActivityThread(615):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-30 23:52:11.129: E/ActivityThread(615):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-30 23:52:11.129: E/ActivityThread(615):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-30 23:52:11.129: E/ActivityThread(615):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-30 23:52:11.129: E/ActivityThread(615):  at java.lang.Thread.run(Thread.java:856)
12-30 23:52:11.238: E/StrictMode(615): null
12-30 23:52:11.238: E/StrictMode(615): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d332e8 that was originally bound here
12-30 23:52:11.238: E/StrictMode(615):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-30 23:52:11.238: E/StrictMode(615):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-30 23:52:11.238: E/StrictMode(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-30 23:52:11.238: E/StrictMode(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-30 23:52:11.238: E/StrictMode(615):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-30 23:52:11.238: E/StrictMode(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-30 23:52:11.238: E/StrictMode(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-30 23:52:11.238: E/StrictMode(615):  at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
12-30 23:52:11.238: E/StrictMode(615):  at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
12-30 23:52:11.238: E/StrictMode(615):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
12-30 23:52:11.238: E/StrictMode(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-30 23:52:11.238: E/StrictMode(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-30 23:52:11.238: E/StrictMode(615):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-30 23:52:11.238: E/StrictMode(615):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-30 23:52:11.238: E/StrictMode(615):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-30 23:52:11.238: E/StrictMode(615):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-30 23:52:11.238: E/StrictMode(615):  at java.lang.Thread.run(Thread.java:856)
12-30 23:52:11.272: W/ActivityManager(290): Unbind failed: could not find connection for android.os.BinderProxy@40fb7e78
12-30 23:52:11.328: E/ActivityThread(615): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d32ef0 that was originally bound here
12-30 23:52:11.328: E/ActivityThread(615): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d32ef0 that was originally bound here
12-30 23:52:11.328: E/ActivityThread(615):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-30 23:52:11.328: E/ActivityThread(615):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-30 23:52:11.328: E/ActivityThread(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-30 23:52:11.328: E/ActivityThread(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-30 23:52:11.328: E/ActivityThread(615):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-30 23:52:11.328: E/ActivityThread(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-30 23:52:11.328: E/ActivityThread(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-30 23:52:11.328: E/ActivityThread(615):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
12-30 23:52:11.328: E/ActivityThread(615):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
12-30 23:52:11.328: E/ActivityThread(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-30 23:52:11.328: E/ActivityThread(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-30 23:52:11.328: E/ActivityThread(615):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-30 23:52:11.328: E/ActivityThread(615):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-30 23:52:11.328: E/ActivityThread(615):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-30 23:52:11.328: E/ActivityThread(615):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-30 23:52:11.328: E/ActivityThread(615):  at java.lang.Thread.run(Thread.java:856)
12-30 23:52:11.398: E/StrictMode(615): null
12-30 23:52:11.398: E/StrictMode(615): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d32ef0 that was originally bound here
12-30 23:52:11.398: E/StrictMode(615):  at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
12-30 23:52:11.398: E/StrictMode(615):  at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
12-30 23:52:11.398: E/StrictMode(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1418)
12-30 23:52:11.398: E/StrictMode(615):  at android.app.ContextImpl.bindService(ContextImpl.java:1407)
12-30 23:52:11.398: E/StrictMode(615):  at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
12-30 23:52:11.398: E/StrictMode(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
12-30 23:52:11.398: E/StrictMode(615):  at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
12-30 23:52:11.398: E/StrictMode(615):  at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
12-30 23:52:11.398: E/StrictMode(615):  at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
12-30 23:52:11.398: E/StrictMode(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
12-30 23:52:11.398: E/StrictMode(615):  at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
12-30 23:52:11.398: E/StrictMode(615):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-30 23:52:11.398: E/StrictMode(615):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-30 23:52:11.398: E/StrictMode(615):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-30 23:52:11.398: E/StrictMode(615):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-30 23:52:11.398: E/StrictMode(615):  at java.lang.Thread.run(Thread.java:856)
12-30 23:52:11.448: W/ActivityManager(290): Unbind failed: could not find connection for android.os.BinderProxy@40f92598

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

 <Button
 android:id="@+id/dmute"
 style="?android:attr/buttonStyleSmall"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginLeft="3dp"
 android:minHeight="30dp"
 android:minWidth="48dp"
 android:text="Mute" />

 <Button
 android:id="@+id/dreset"
 style="?android:attr/buttonStyleSmall"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginLeft="198dp"
 android:minHeight="30dp"
 android:minWidth="48dp"
 android:text="Reset" />
</LinearLayout>

 <LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal"
 android:paddingTop="20dp" >

 <TextView
 android:id="@+id/dcount"
 android:layout_width="0dip"
 android:layout_height="wrap_content"
 android:layout_weight="90"
 android:gravity="center"
 android:singleLine="true"
 android:text="Numbers"
 android:textSize="25sp" />

 <Button
 android:id="@+id/addtototal1"
 style="?android:attr/buttonStyleSmall"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_weight="5"
 android:text="+ to Total" />

  </LinearLayout>

  <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:paddingTop="20dp" >

  <EditText
  android:id="@+id/enteramount"
  android:layout_width="0dip"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:layout_weight="90"
  android:gravity="center"
  android:hint="Enter Amount"
  android:inputType="number"
  android:singleLine="true"
  android:textSize="25sp" />

  <Button
  android:id="@+id/addtototal2"
  style="?android:attr/buttonStyleSmall"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_weight="5"
  android:text="+ to Total" />

 </LinearLayout>

 <LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal"
 android:paddingTop="20dp" >

 <TextView
 android:id="@+id/totalCount"
 android:layout_width="0dip"
 android:layout_height="wrap_content"
 android:layout_gravity="center"
 android:layout_weight="80"
 android:gravity="center"
 android:singleLine="true"
 android:textSize="25sp" />

  <Button
  android:id="@+id/cleartotal"
  style="?android:attr/buttonStyleSmall"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Clear" />

 </LinearLayout>

  <Button
  android:id="@+id/dclick"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center"
  android:layout_marginTop="30dp"
  android:height="120dp"
  android:width="250dp" />

</LinearLayout>
  • 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-16T12:48:42+00:00Added an answer on June 16, 2026 at 12:48 pm

    You have to initialize Your button addtotal1:

        addtotal1 = (Button)findViewById(R.id.yourButtonId);
    

    before You could set onClickListener.

    EDIT

    Your xml EditText has only the inputType “number”, so the user can´t put some decimal values. If You want it like this, You don´t need double variables. Instead of double, use int, so Your result is without showing decimal point:

           public class durood extends Activity{
    
             private TextView txtCount;
             private TextView totalCount;
             private EditText enteramount;
             private Button btnCount;
             private Button addtotal1;
             private Button addtotal2;
             private Button cleartotal;
             private static int count=0;
             private int x=0;
             private int y=0;
             private int z=0;
    
              @Override
               public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
                // The activity is being created.
                setContentView(R.layout.durood);
    
                enteramount = (EditText)findViewById(R.id.enteramount);
                totalCount = (TextView)findViewById(R.id.totalCount);
                addtotal1=(Button)findViewById(R.id.addtototal1);
                addtotal2=(Button)findViewById(R.id.addtototal2);
    
    
                //add to total 1
                addtotal1.setOnClickListener(new View.OnClickListener() {
                  public void onClick(View v) {
    
                  x=Integer.parseInt(enteramount.getText().toString());
                  y=Integer.parseInt(totalCount.getText().toString());
                  z=x+y;
                  totalCount.setText(Integer.toString(z));
                  //to set value of enteramount to 0
                  enteramount.setText("0"); //or enteramaount.setText("") if You want show nothing
                }
    
    
               });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace

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.