1
votes

I have two questions:

  1. How do I adjust the buttons in a table, like a normal calculator?
  2. Whenever I click the 'equal' button the app is closing -Force Close.

I think the problem comes from the int sum=0; whenever I use it at the equal place it gives the error.

code

2
always look at LogCat to see the stack trace. In most cases it exactly tells why and where it crashed. - Marcin Orlowski

2 Answers

0
votes

use this code it may help

display.setText(sum+"");

because you have declared sum as int and setText property accepts CharSequence

0
votes

For adjusting buttons, use TableLayout or RelativeLayout, where you can position buttons relatively to others. Concerning second question, just change

display.setText(sum);

to

display.setText(String.valueOf(sum));

To make your calculator work at least a little bit change equal.setOnClickListener to this:

equal.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                            // TODO Auto-generated method stub

                            display.setText(String.valueOf(counter+sum));
                            counter=0;
                            sum=0;
                    }
            });