Calculator App Problem :)

This is a discussion on Calculator App Problem :) within the Beginning Developers forums, part of the Android Development category; Hello all I am new here and also new to Android .. I want to build a simple calculator app.. I have finished the display ...

Results 1 to 2 of 2

Thread: Calculator App Problem :)

  1. #1
    Android Lurker 0Ajax0's Avatar
    Join Date
    Feb 2012
    Posts
    1

    Calculator App Problem :)

    Hello all I am new here and also new to Android ..
    I want to build a simple calculator app..
    I have finished the display in an xml file..
    But i do not know how to make the text appear on the Editor when i press the corresponding button
    Any Help will be amazing.. i have been sittting with this all day..


    also.. the moment I connect the editor to the activity file.. the calculator crashed.. any EditText variable or a reference to the EditText Id in XML also crashes..
    this is for 1.5 android..

    I will enter the source code.
    This is the XML
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        
    
    
    <TextView android:id="@+id/label"
             android:layout_width="wrap_content" 
             android:layout_height="wrap_content"
             android:text="Calculator"
              android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"/>
    
    
    <View android:id="@+id/alignhelper"
          android:layout_width="fill_parent"
          android:layout_height="4dp"
          android:layout_alignParentBottom="true" />
    
    
        <EditText
            android:id="@+id/entry"
             android:hint="Perform Calculation..."
             android:layout_below="@id/label"
              android:layout_width="fill_parent"
            android:layout_height="80dip"
            
            
            android:background="@android:drawable/editbox_background"
             android:layout_alignParentTop="false" />
        
    <TableLayout  android:id="@+id/row1"
         android:layout_width="fill_parent"
            android:layout_height="wrap_content"
             android:layout_below="@+id/entry"
       
       android:layout_above="@+id/alignhelper"   >
       
       <TableRow android:layout_weight="1">
          
          <Button android:id="@+id/plus"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="+"
              android:layout_weight="1"
               />
       
          
          <Button android:id="@+id/minus"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="-"
              android:layout_weight="1" />
          
          <Button android:id="@+id/mul"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="*"
              android:layout_weight="1" />
          
          <Button android:id="@+id/div"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="/"
              android:layout_weight="1" />
       </TableRow>
    <TableRow android:layout_weight="1">
          
         
        <Button android:id="@+id/n7"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="7"
              android:layout_weight="1" />
          
          <Button android:id="@+id/n8"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="8"
              android:layout_weight="1" />
          
          <Button android:id="@+id/n9"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="9"
              android:layout_weight="1" />
          
          <Button android:id="@+id/perc"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="%"
              android:layout_weight="1" />
       </TableRow>
       <TableRow android:layout_weight="1">
          
          <Button android:id="@+id/n4"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="4"
              android:layout_weight="1" />
       
          
          <Button android:id="@+id/n5"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="5"
              android:layout_weight="1" />
          
          <Button android:id="@+id/n6"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="6"
              android:layout_weight="1" />
          
          <Button android:id="@+id/equal"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="="
              android:layout_weight="1" />
       </TableRow>
    <TableRow android:layout_weight="1">
          
          <Button android:id="@+id/n1"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="1"
              
              android:layout_weight="1" />
       
          
          <Button android:id="@+id/n2"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="2"
              android:layout_weight="1" />
          
          <Button android:id="@+id/n3"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="3"
              android:layout_weight="1" />
          
          <Button android:id="@+id/n0"
              android:layout_width="0dip"
              android:layout_height="fill_parent"
              android:text="0"
              android:layout_weight="1" />
       </TableRow>
       
    </TableLayout>
    
    
        
    </RelativeLayout>

    This is the Activity

    Code:
    package com.calc.proj;
    
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.preference.EditTextPreference;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    
    public class CalculatorActivity extends Activity{
        /** Called when the activity is first created. */
    	
    	private TextView inpview1;
     /*   private EditText input2;
        private EditText input3;
        private EditText input4;
        private EditText input5;
        private EditText input6;
        private EditText input7;
        private EditText input8;
        private EditText input9;
        private EditText input0;
        private EditText solution;*/
       // private CalculatorActivity mContext;
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
         //   mContext=this;
           setContentView(R.layout.main);
            
           
         //  inpview1= (TextView) findViewById(R.id.n1);
           
            final Button inp1 =(Button)findViewById(R.id.n1);
          /*  input2=(EditText)findViewById(R.id.n2);
            input3=(EditText)findViewById(R.id.n3);
            input4=(EditText)findViewById(R.id.n4);
            input5=(EditText)findViewById(R.id.n5);
            input6=(EditText)findViewById(R.id.n6);
            input7=(EditText)findViewById(R.id.n7);
            input8=(EditText)findViewById(R.id.n8);
            input9=(EditText)findViewById(R.id.n9);
            input0=(EditText)findViewById(R.id.n0);
    
    
            solution = (EditText) findViewById(R.id.equal);
            
            Button plusB= (Button) findViewById(R.id.plus);        
            Button plusS= (Button) findViewById(R.id.minus);  
            Button plusM= (Button) findViewById(R.id.mul);   
            Button plusD= (Button) findViewById(R.id.div);  
            */
            
    
    
    //what do i enter here.. to get the input displayed on my editor ? :)
    //thanks.. i do not expect spoon feeding..even a point in the right direction would help:)
    //also.. I tried a OnClickListener.. nothing happens.. :(
            
            
    }
    
    
    }

  2. Android.net is the premier Android Forum. Registered users do not see these ads. .

  3. #2
    Super Moderator/RS furbearingmammal's Avatar
    Join Date
    Jan 2011
    Location
    Two hours north of Syracuse, NY. Yes, there IS civilization that far north.
    Posts
    3,983
    Thanked
    197 times
    Twitter
    FurryVarmint
    Thread moved to appropriate forum.

    to the forum!
    DO NOT WRITE IN THIS SPACE
    THIS SPACE INTENTIONALLY LEFT BLANK

Remove Ads

http://www.scramblerducati.org/

Sponsored Links

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Similar Threads

  1. Tip Calculator
    By Mabelle71 in forum LG Ally Help
    Replies: 1
    Last Post: 05-15-2011, 06:06 PM

Search tags for this page

a simple calculator in android code
,
android calculator application source code
,
android forum
,

android pg calculator source code

,

calculator button problems with android

,
calculator code in android application
,
easy calculator app issue android
,
problems with android calculator
,
scientific calculator xml code in android
,

simple calculator android app code

,
simple calculator android source code
,
simple calculator in android source code
,
simple calculator source code in android
,
source code for android calculator app
,
source code for scientific calculator in android
Click on a term to search our sites for related topics.
Android Forum