kafa.gitti
kafa.gitti

Reputation: 25

How can I calculate the values entered in edittext and transfer from one activity to another?

I am devoloping a roof calculater. i have three edittext and calculate button in the first activity. In the second activity i have a textview that shows the result.

    EditText editText1Değer1Kod;
    EditText editText2Değer2Kod;
    EditText editText3Değer3Kod;

    Button hesaplaKod;

I want to take these three value then calculate with formula then show the result in second activity as a textview. How can i calculate (sum or add this three value) then show in the second activity?

Upvotes: 0

Views: 1929

Answers (2)

Jitendra
Jitendra

Reputation: 1125

Use in first Activity

hesaplaKod.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                int value1= Integer.parseInt(EditText01.getText().toString());
                int value2= Integer.parseInt(EditText01.getText().toString());
                int value3= Integer.parseInt(EditText01.getText().toString());

                int add = value1+value2+value3;

                Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
                intent.putExtra("AddValue", add);
                startActivity(intent);
            }
        });

And in onCreate of Second Activity get the value from this

int addvalue = getIntent().getExtras().getInt("AddValue");

Upvotes: 1

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

enter code herejust pass calculate the number and pass the using intent to other activity

in First Activity :

Intent intent=new Intent(IntentsDemo2.this,Activity2.class);
   intent.putExtra("result", result);
   startActivity(intent);

in Second Activity :

@Override

  public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main2);
         Intent sender=getIntent();
         int result =sender.getExtras().getInt("result");
}

Upvotes: 1

Related Questions