الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

لقد صنعت آلة حاسبة للاندرويد ليس بها خطأ لكنها لا تعمل . لماذا ؟

بدأه Osama ahmad 1999 في 23 نوفمبر 2013 · 3 رد · 479 مشاهدة · في Android
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

لقد قمت بعمل آلة حاسبة للاندرويد ولم يظهر لي اي خطا مطلقا في ملف ال xml او حتى ملف الjava وعندما افتحه في الموبايل الوهمي او المحاكي او الemulatour الخاص بالeclipse فانه يظهر خطا ويقفل في الحال فهل من حل لهذه المشكلة ؟


 


 


المشروع : https://www.mediafire.com/?os673exdou5qgjf


 


 


ملف ال xml :


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/ScrollView1"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".Main" >


    <RelativeLayout

        android:layout_width="287dp"

        android:layout_height="417dp" >


        <EditText

            android:id="@+id/editText1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentRight="true"

            android:layout_alignParentTop="true"

            android:layout_marginRight="39dp"

            android:ems="10"

            android:inputType="numberDecimal" >


            <requestFocus />

        </EditText>


        <Button

            android:id="@+id/BackSpace"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/editText1"

            android:layout_alignRight="@+id/Two"

            android:layout_below="@+id/editText1"

            android:text="BackSpace" />


         <Button

            android:id="@+id/One"

            android:layout_below="@+id/BackSpace"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/editText1"

            android:text="1" />


        <Button

            android:id="@+id/Two"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/One"

            android:layout_alignBottom="@+id/One"

            android:layout_toRightOf="@+id/One"

            android:text="2" />


        <Button

            android:id="@+id/Three"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/Two"

            android:layout_alignBottom="@+id/Two"

            android:layout_toRightOf="@+id/Two"

            android:text="3" />


        <Button

            android:id="@+id/Four"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/One"

            android:layout_below="@+id/One"

            android:text="4" />


        <Button

            android:id="@+id/Five"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/Four"

            android:layout_alignBottom="@+id/Four"

            android:layout_toRightOf="@+id/Four"

            android:text="5" />


        <Button

            android:id="@+id/Six"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/Five"

            android:layout_alignBottom="@+id/Five"

            android:layout_toRightOf="@+id/Five"

            android:text="6" />


        <Button

            android:id="@+id/Seven"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/Four"

            android:layout_below="@+id/Four"

            android:text="7" />


        <Button

            android:id="@+id/Eight"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/Seven"

            android:layout_alignBottom="@+id/Seven"

            android:layout_alignLeft="@+id/Five"

            android:text="8" />


        <Button

            android:id="@+id/Nine"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/Eight"

            android:layout_alignBottom="@+id/Eight"

            android:layout_alignLeft="@+id/Six"

            android:text="9" />


        <Button

            android:id="@+id/dot"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_below="@+id/Seven"

            android:layout_toLeftOf="@+id/Eight"

            android:text="." />


        <Button

            android:id="@+id/Ziro"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/dot"

            android:layout_alignBottom="@+id/dot"

            android:layout_alignLeft="@+id/Eight"

            android:text="0" />


        <ImageView

            android:id="@+id/imageView1"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignParentLeft="true"

            android:layout_alignParentRight="true"

            android:layout_below="@+id/dot"

            android:src="@drawable/kk" />


        <Button

            android:id="@+id/plus"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/dot"

            android:layout_below="@+id/imageView1"

            android:text="+" />


        <Button

            android:id="@+id/minus"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/plus"

            android:layout_alignBottom="@+id/plus"

            android:layout_toRightOf="@+id/plus"

            android:text="-" />


        <Button

            android:id="@+id/Multiplication"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/plus"

            android:layout_below="@+id/plus"

            android:text="*" />


        <Button

            android:id="@+id/Division"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignBaseline="@+id/Multiplication"

            android:layout_alignBottom="@+id/Multiplication"

            android:layout_alignLeft="@+id/minus"

            android:text="/" />


        <Button

            android:id="@+id/Eqals"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/Multiplication"

            android:layout_alignRight="@+id/Division"

            android:layout_below="@+id/Multiplication"

            android:text="=" />


        <Button

            android:id="@+id/c"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_below="@+id/editText1"

            android:layout_toRightOf="@+id/Two"

            android:text="Clear" />


        <Button

            android:id="@+id/AddMinus"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_below="@+id/Eight"

            android:layout_toRightOf="@+id/Eight"

            android:text="- +" />


        <Button

            android:id="@+id/sqrt"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/X"

            android:layout_alignParentBottom="true"

            android:text="sqrt" />


        <Button

            android:id="@+id/X"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/AddMinus"

            android:layout_below="@+id/minus"

            android:text="1/x" />


        <Button

            android:id="@+id/Power"

            android:layout_width="70dp"

            android:layout_height="wrap_content"

            android:layout_alignLeft="@+id/X"

            android:layout_below="@+id/imageView1"

            android:text="x^" />


    </RelativeLayout>


</ScrollView>

ملف ال java :


package com.calculatour;


import android.os.Bundle;

import android.app.Activity;

import android.content.Context;

import android.view.Menu;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;


public class Main extends Activity {

	 private double valHolder1;

		private double valHolder2;

		private double tmpValue;

		private boolean hasDecimal;

		private boolean inputStatus;

		public String calcFunc;


		Button one = (Button)findViewById(R.id.One);

		Button two = (Button)findViewById(R.id.Two);

		Button three = (Button)findViewById(R.id.Three);

		Button four = (Button)findViewById(R.id.Four);

		Button five = (Button)findViewById(R.id.Five);

		Button six = (Button)findViewById(R.id.Six);

		Button seven = (Button)findViewById(R.id.Seven);

		Button eight = (Button)findViewById(R.id.Eight);

		Button nine = (Button)findViewById(R.id.Nine);

		Button ziro = (Button)findViewById(R.id.Ziro);




		Button addminus = (Button)findViewById(R.id.AddMinus);

		Button x = (Button)findViewById(R.id.X);

		Button dot = (Button)findViewById(R.id.dot);

		Button clear = (Button)findViewById(R.id.c);

		Button backspace = (Button)findViewById(R.id.BackSpace);

		Button sqrt = (Button)findViewById(R.id.sqrt);

		Button power = (Button)findViewById(R.id.Power);




		Button minus = (Button)findViewById(R.id.minus);

		Button plus = (Button)findViewById(R.id.plus);

		Button division = (Button)findViewById(R.id.Division);

		Button multiplicate = (Button)findViewById(R.id.Multiplication);

		Button equals = (Button)findViewById(R.id.Eqals);




		final EditText sourse = (EditText)findViewById(R.id.editText1);




		@Override

		public boolean onCreateOptionsMenu(Menu menu) {

			// Inflate the menu; this adds items to the action bar if it is present.

			getMenuInflater().inflate(R.menu.main, menu);

			return true;

		}




	@Override

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);









one.setOnClickListener(new OnClickListener() {


			@Override

			public void onClick(View v) {


				 try

				 {

					 if (inputStatus == false)

					 {

								sourse.setText(sourse.getText()+"1");

							}

							else

							{

								sourse.setText("1");

								inputStatus = false;

							}			}


						catch (RuntimeException ex)

						{

error();

						}}


		});




two.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {


		try

		{

			if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"2");

					}

					else

					{

						sourse.setText("2");

						inputStatus = false;

							}

		}

		catch (RuntimeException ex)

		{

			error();

		}


			}

});




three.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"3");

					}

					else

					{

						sourse.setText("3");

						inputStatus = false;

							}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 		}

});




four.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"4");

					}

					else

					{

						sourse.setText("4");

						inputStatus = false;

							}	

			}

			catch (RuntimeException ex)

			{

	        error();

			}

			}

});




five.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"5");

					}

					else

					{

						sourse.setText("5");

						inputStatus = false;

							}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 if (inputStatus == false)

		 {

					sourse.setText(sourse.getText()+"5");

				}

				else

				{

					sourse.setText("5");

					inputStatus = false;

						}	}

});




six.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"6");

					}

					else

					{

						sourse.setText("6");

						inputStatus = false;

							}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 if (inputStatus == false)

		 {

					sourse.setText(sourse.getText()+"6");

				}

				else

				{

					sourse.setText("6");

					inputStatus = false;

						}	}

});




seven.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"7");

					}

					else

					{

						sourse.setText("7");

						inputStatus = false;

							}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 	}

});




eight.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"8");

					}

					else

					{

						sourse.setText("8");

						inputStatus = false;

							}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

			}

});




nine.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"9");

					}

					else

					{

						sourse.setText("9");

						inputStatus = false;

							}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 	}

});




ziro.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						sourse.setText(sourse.getText()+"0");

					}

					else

					{

						sourse.setText("0");

						inputStatus = false;

							}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 	}

});




clear.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 sourse.setText("");

				valHolder1 = 0;

				valHolder2 = 0;

				calcFunc = "";

				hasDecimal = false;

			}

			catch (RuntimeException ex)

			{

	        error();

			}


	}

});




dot.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (! inputStatus)

				{

					if (! hasDecimal)

					{

						if (sourse.getText().length() > 1)

						{


								sourse.setText(sourse.getText()+".");

								hasDecimal = true;

							}

						}

						else

						{

							sourse.setText("0.");

						}


				}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		}

});



equals.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0 && valHolder1 != 0)

				{

							CalculateTotals();

							calcFunc = "";

							hasDecimal = false;

						}

			}

			catch (RuntimeException ex)

			{

	        error();

			}



	}

});	


plus.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0)

			 {

						if (calcFunc.equals(""))

						{

							valHolder1 = Double.parseDouble(sourse.getText().toString());

							sourse.setText("");

						}

						else

						{

							CalculateTotals();

						}

						calcFunc = "Add";

						hasDecimal = false;

					}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 }

});	






minus.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0)

			 {

						if (calcFunc.equals(""))

						{

							valHolder1 = Double.parseDouble(sourse.getText().toString());

							sourse.setText("");

						}

						else

						{

							CalculateTotals();

						}

						calcFunc = "Subtract";

						hasDecimal = false;

					}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		 }

});	




multiplicate.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0)

			 {

						if (calcFunc.equals(""))

						{

							valHolder1 = Double.parseDouble(sourse.getText().toString());

							sourse.setText("");

						}

						else

						{

							CalculateTotals();

						}

						calcFunc = "Multiply";

						hasDecimal = false;

					}


			}

			catch (RuntimeException ex)

			{

	        error();

			}


	}

});	




division.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0)

			 {

						if (calcFunc.equals(""))

						{

							valHolder1 = Double.parseDouble(sourse.getText().toString());

							sourse.setText("");

						}

						else

						{

							CalculateTotals();

						}

						calcFunc = "Divide";

						hasDecimal = false;

					}

			}

			catch (RuntimeException ex)

			{

	        error();

			}


	}



});	






addminus.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (inputStatus == false)

			 {

						if (sourse.getText().length() > 0)

						{

							valHolder1 = -1 * Double.parseDouble(sourse.getText().toString());

							sourse.setText(String.valueOf(valHolder1));

						}

					}

			}

			catch (RuntimeException ex)

			{

	        error();

			}


	}



});





x.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0)

			 {

						tmpValue = Double.parseDouble(sourse.getText().toString());

						tmpValue = 1 / tmpValue;

						sourse.setText(String.valueOf(tmpValue));

						hasDecimal = false;

					}

			}

			catch (RuntimeException ex)

			{

	        error();

			}




};






});



power.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0)

			  {

						if (calcFunc.equals(""))

						{

							valHolder1 = Double.parseDouble(sourse.getText().toString());

							sourse.setText("");

						}

						else

						{

							CalculateTotals();

						}

						calcFunc = "PowerOf";

						hasDecimal = false;

					}	

			}

			catch (RuntimeException ex)

			{

	        error();

			}


	}

});




sqrt.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 if (sourse.getText().length() != 0)

			  {


				 			tmpValue = Double.parseDouble(sourse.getText().toString());

				 			tmpValue = Math.sqrt(tmpValue);

				 			sourse.setText(String.valueOf(tmpValue));

				 			hasDecimal = false;

				 		}

			}

			catch (RuntimeException ex)

			{

	        error();

			}



	}

});




backspace.setOnClickListener(new OnClickListener() {


	@Override

	public void onClick(View v) {

		 try

	        {

			 String str = null;

				int loc = 0;

				if (sourse.getText().length() != 0)

				{

					str = String.valueOf(sourse.getText().charAt(sourse.getText().length() - 1));

					if (str.equals("."))

					{

						hasDecimal = false;

					}

					loc = sourse.getText().length();

					sourse.setText(sourse.getText().delete(((loc - 1)), 1));

				}

			}

			catch (RuntimeException ex)

			{

	        error();

			}

		  }

});




	}


	private void CalculateTotals()

	{

		 try

	        {

			 valHolder2 = Double.parseDouble(sourse.getText().toString());


				if (calcFunc == "Add")

					valHolder1 = valHolder1 + valHolder2;

				if (calcFunc == "Subtract")

					valHolder1 = valHolder1 - valHolder2;

				if (calcFunc == "Divide")

					valHolder1 = valHolder1 / valHolder2;

				if (calcFunc == "Multiply")

					valHolder1 = valHolder1 * valHolder2;

				if (calcFunc == "PowerOf")

					valHolder1 = Math.pow(valHolder1, valHolder2);


				sourse.setText(String.valueOf(valHolder1));

				inputStatus = true;

			}

			catch (RuntimeException ex)

			{

	        error();

			}




		}


	private void error()

	{

		try

        {

Context context = getApplicationContext();

		CharSequence text = "Error";

		int duration = Toast.LENGTH_SHORT;


		Toast toast = Toast.makeText(context, text, duration);

		toast.show();

		}

		catch (RuntimeException ex)

		{

		}



		}

}

تم تعديل هذه المشاركة بواسطة Osama ahmad 1999 في 23 نوفمبر 2013 في 19:10

#2

إليك الشيفرة بعد التصحيح 

package com.calculatour;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Main extends Activity {

	private double valHolder1;
	private double valHolder2;
	private double tmpValue;
	private boolean hasDecimal;
	private boolean inputStatus;
	public String calcFunc;

	EditText sourse;

	// numeric
	Button one;
	Button two;
	Button three;
	Button four;
	Button five;
	Button six;
	Button seven;
	Button eight;
	Button nine;
	Button ziro;

	// operator
	Button addminus;
	Button x;
	Button dot;
	Button clear;
	Button backspace;
	Button sqrt;
	Button power;

	// operator
	Button minus;
	Button plus;
	Button division;
	Button multiplicate;
	Button equals;

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

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		initUI();
		one.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "1");
					}
					else {
						sourse.setText("1");
						inputStatus = false;
					}
				}

				catch (RuntimeException ex) {
					;
				}
			}

		});

		two.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "2");
					}
					else {
						sourse.setText("2");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}

			}
		});

		three.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "3");
					}
					else {
						sourse.setText("3");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		four.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "4");
					}
					else {
						sourse.setText("4");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		five.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "5");
					}
					else {
						sourse.setText("5");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
				if (inputStatus == false) {
					sourse.setText(sourse.getText() + "5");
				}
				else {
					sourse.setText("5");
					inputStatus = false;
				}
			}
		});

		six.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "6");
					}
					else {
						sourse.setText("6");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
				if (inputStatus == false) {
					sourse.setText(sourse.getText() + "6");
				}
				else {
					sourse.setText("6");
					inputStatus = false;
				}
			}
		});

		seven.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "7");
					}
					else {
						sourse.setText("7");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		eight.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "8");
					}
					else {
						sourse.setText("8");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		nine.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "9");
					}
					else {
						sourse.setText("9");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		ziro.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						sourse.setText(sourse.getText() + "0");
					}
					else {
						sourse.setText("0");
						inputStatus = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		clear.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					sourse.setText("");
					valHolder1 = 0;
					valHolder2 = 0;
					calcFunc = "";
					hasDecimal = false;
				} catch (RuntimeException ex) {
					;
				}

			}
		});

		dot.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (!inputStatus) {
						if (!hasDecimal) {
							if (sourse.getText().length() > 1) {

								sourse.setText(sourse.getText() + ".");
								hasDecimal = true;
							}
						}
						else {
							sourse.setText("0.");
						}

					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		equals.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0 && valHolder1 != 0) {
						CalculateTotals();
						calcFunc = "";
						hasDecimal = false;
					}
				} catch (RuntimeException ex) {
					;
				}

			}
		});

		plus.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0) {
						if (calcFunc.equals("")) {
							valHolder1 = Double.parseDouble(sourse.getText().toString());
							sourse.setText("");
						}
						else {
							CalculateTotals();
						}
						calcFunc = "Add";
						hasDecimal = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		minus.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0) {
						if (calcFunc.equals("")) {
							valHolder1 = Double.parseDouble(sourse.getText().toString());
							sourse.setText("");
						}
						else {
							CalculateTotals();
						}
						calcFunc = "Subtract";
						hasDecimal = false;
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

		multiplicate.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0) {
						if (calcFunc.equals("")) {
							valHolder1 = Double.parseDouble(sourse.getText().toString());
							sourse.setText("");
						}
						else {
							CalculateTotals();
						}
						calcFunc = "Multiply";
						hasDecimal = false;
					}

				} catch (RuntimeException ex) {
					;
				}

			}
		});

		division.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0) {
						if (calcFunc.equals("")) {
							valHolder1 = Double.parseDouble(sourse.getText().toString());
							sourse.setText("");
						}
						else {
							CalculateTotals();
						}
						calcFunc = "Divide";
						hasDecimal = false;
					}
				} catch (RuntimeException ex) {
					;
				}

			}

		});

		addminus.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (inputStatus == false) {
						if (sourse.getText().length() > 0) {
							valHolder1 = -1 * Double.parseDouble(sourse.getText().toString());
							sourse.setText(String.valueOf(valHolder1));
						}
					}
				} catch (RuntimeException ex) {
					;
				}

			}

		});

		x.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0) {
						tmpValue = Double.parseDouble(sourse.getText().toString());
						tmpValue = 1 / tmpValue;
						sourse.setText(String.valueOf(tmpValue));
						hasDecimal = false;
					}
				} catch (RuntimeException ex) {
					;
				}

			};

		});

		power.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0) {
						if (calcFunc.equals("")) {
							valHolder1 = Double.parseDouble(sourse.getText().toString());
							sourse.setText("");
						}
						else {
							CalculateTotals();
						}
						calcFunc = "PowerOf";
						hasDecimal = false;
					}
				} catch (RuntimeException ex) {
					;
				}

			}
		});

		sqrt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					if (sourse.getText().length() != 0) {

						tmpValue = Double.parseDouble(sourse.getText().toString());
						tmpValue = Math.sqrt(tmpValue);
						sourse.setText(String.valueOf(tmpValue));
						hasDecimal = false;
					}
				} catch (RuntimeException ex) {
					;
				}

			}
		});

		backspace.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				try {
					String str = null;
					int loc = 0;
					if (sourse.getText().length() != 0) {
						str = String
								.valueOf(sourse.getText().charAt(sourse.getText().length() - 1));
						if (str.equals(".")) {
							hasDecimal = false;
						}
						loc = sourse.getText().length();
						sourse.setText(sourse.getText().delete(((loc - 1)), 1));
					}
				} catch (RuntimeException ex) {
					;
				}
			}
		});

	}

	private void initUI() {
		one = (Button) findViewById(R.id.One);
		two = (Button) findViewById(R.id.Two);
		three = (Button) findViewById(R.id.Three);
		four = (Button) findViewById(R.id.Four);
		five = (Button) findViewById(R.id.Five);
		six = (Button) findViewById(R.id.Six);
		seven = (Button) findViewById(R.id.Seven);
		eight = (Button) findViewById(R.id.Eight);
		nine = (Button) findViewById(R.id.Nine);
		ziro = (Button) findViewById(R.id.Ziro);

		addminus = (Button) findViewById(R.id.AddMinus);
		x = (Button) findViewById(R.id.X);
		dot = (Button) findViewById(R.id.dot);
		clear = (Button) findViewById(R.id.c);
		backspace = (Button) findViewById(R.id.BackSpace);
		sqrt = (Button) findViewById(R.id.sqrt);
		power = (Button) findViewById(R.id.Power);

		minus = (Button) findViewById(R.id.minus);
		plus = (Button) findViewById(R.id.plus);
		division = (Button) findViewById(R.id.Division);
		multiplicate = (Button) findViewById(R.id.Multiplication);
		equals = (Button) findViewById(R.id.Eqals);
		sourse = (EditText) findViewById(R.id.editText1);
	}

	private void CalculateTotals() {
		try {
			valHolder2 = Double.parseDouble(sourse.getText().toString());

			if (calcFunc == "Add")
				valHolder1 = valHolder1 + valHolder2;
			if (calcFunc == "Subtract")
				valHolder1 = valHolder1 - valHolder2;
			if (calcFunc == "Divide")
				valHolder1 = valHolder1 / valHolder2;
			if (calcFunc == "Multiply")
				valHolder1 = valHolder1 * valHolder2;
			if (calcFunc == "PowerOf")
				valHolder1 = Math.pow(valHolder1, valHolder2);

			sourse.setText(String.valueOf(valHolder1));
			inputStatus = true;
		} catch (RuntimeException ex) {
			;
		}

	}

}

لا إله إلا الله محمد رسول الله  

Blog

GitHub

#3

شكرا اخي لكن هناك بعض الازرار لا تعمل بشكل جيد هل يمكنك اصلاحها ؟

زر الBackSpace

زر الsqrt او الجزر التربيعي هل يمكن ان اكتب الرقم فالزر الان يقوم بعمل الجزر التربيعي اي جزر2 فهل يمكن ان عندما اضغط على الزر ثم اكتب الرقم مثلا 3 يقوم بعمل جزر تكعيبي

زر -+ لايقوم بالعمل عندما يظهر التاتج

زر ال . عند الضغط عليه مرتين يقوم بتحويل الرقم المكتوب إلى 0.

وبارك الله فيك اخي الكريم

#4

عفواً أخي الكريم   


ماذكرته بإمكانك إن شاء الله برمجته بسهولة أو يساعدك إن شاء الله أحد الاخوان في المنتدى


سأساعدك  في نطاق عمل  الأندرويد أما تنظيم البرنامج فأفضل شيء  أن تقوم أنت بالتفكير فيه ، سيما ولقد انجزت ٩٠٪ من البرنامج 


بالتوفيق 


لا إله إلا الله محمد رسول الله  

Blog

GitHub

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…