-5

I want to create an app that only contain 3 EditText. (Nothing else)

EditText1

EditText2

EditText3

now

1) If I enter values for EditText1 and EditText2 then addition should be performed between ET1 and ET2 then answer should be set to EditText3.... (ET1+ET2=ET3)

2) If I enter values for EditText1 and EditText3 then subtraction should be performed between ET1 and ET3 then answer should be set to EditText2.... (ET3-ET1=ET2)

  • Do you mean... When you write in a then b and c will change as 1 and 3. When you write on b then a and c will change as formula 1 and 2. like this? –  Aug 20 '17 at 09:47
  • I mean. If I enter values for a and b then c should be calculated and display answer in EditText c for this case, and If I enter values for a and c then b should be calculated and result displayed in EditText b in this case – confused soul Aug 20 '17 at 09:51
  • 2
    too unclear to answer – navylover Aug 20 '17 at 09:53
  • Wait I'll make changes in question – confused soul Aug 20 '17 at 09:54
  • Refer to [this tutorial](http://www.androidauthority.com/build-a-calculator-app-721910/). – Abhi Aug 20 '17 at 09:55
  • 3
    Welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour), have a look around, and read through the [help center](https://stackoverflow.com/help) , in particular [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [What topics can I ask about here?](https://stackoverflow.com/help/on-topic). – Yagami Light Aug 20 '17 at 09:57
  • @confused soul right .... if you want to do so.... you need to think like this...You can not edit 2 EditText at a time. so edit in a means c and b will change.. –  Aug 20 '17 at 09:59
  • 1
    Suggestion: change your alias from `confused soul` to `brain fog`... joking ;) – Phantômaxx Aug 20 '17 at 10:04

1 Answers1

0

It's sounds crazy but I think, "Not done before! Not mean that could not be done ever."

@confused soul , I found solution for your crazy question...

Xml for EditText

 <EditText
      android:id="@+id/et_a"
      android:layout_width="0dp"
      android:layout_height="40dp"
      android:layout_weight="0.16"
      android:gravity="center"
      android:inputType="number" />

 <EditText
      android:id="@+id/et_b"
      android:layout_width="0dp"
      android:layout_height="40dp"
      android:layout_weight="0.16"
      android:gravity="center"
      android:inputType="number" />

 <EditText
      android:id="@+id/et_c"
      android:layout_width="0dp"
      android:layout_height="40dp"
      android:layout_weight="0.16"
      android:gravity="center"
      android:inputType="number"/>
 </LinearLayout>

Code I have done for solution...

public class MainActivity extends AppCompatActivity {

EditText et_a, et_b,et_c;

String whereChanging = "a";
String whereFocusing = "a";
String whereLoseFocusing = "b";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    et_a = (EditText) findViewById(R.id.et_a);
    et_b = (EditText) findViewById(R.id.et_b);
    et_c = (EditText) findViewById(R.id.et_c);

    et_a.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus) {
                whereFocusing = "a";
                Log.e("Focus", "A is Focusing....");
            }else{
                whereLoseFocusing = "a";
                Log.e("LoseFocus", "A is Lose it's Focus....");
            }
        }
    });

    et_b.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus) {
                whereFocusing = "b";
                Log.e("Focus", "B is Focusing....");
            }else{
                whereLoseFocusing = "b";
                Log.e("LoseFocus", "B is Lose it's Focus....");
            }
        }
    });

    et_c.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus) {
                whereFocusing = "c";
                Log.e("Focus", "C is Focusing....");
            }else{
                whereLoseFocusing = "c";
                Log.e("LoseFocus", "C is Lose it's Focus....");
            }
        }
    });


    et_a.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        public void beforeTextChanged(CharSequence s, int start, int count,int after) {
            if(whereFocusing.equals("a")){
                whereChanging = "a";
            }
        }

        public void afterTextChanged(Editable s) {

            if(whereFocusing.equals("a") && whereLoseFocusing.equals("b")) {
                try {
                    if (whereChanging.equals("a")) {
                        Log.e("Typing", "A is typing....");
                        if (s.length() > 0) {
                            int a_input = Integer.parseInt(s.toString());
                            String b_text = et_b.getText().toString();
                            int b_input = 0;
                            if (!b_text.isEmpty()) {
                                b_input = Integer.parseInt(b_text);
                            }
                            et_c.setText((a_input + b_input) + "");
                        }
                    }
                } catch (Exception exception) {
                    Log.e("Err", exception.toString() + "");
                }
            }else if(whereFocusing.equals("a") && whereLoseFocusing.equals("c")) {
                try {
                    if (whereChanging.equals("a")) {
                        Log.e("Typing", "A is typing....");
                        if (s.length() > 0) {
                            int a_input = Integer.parseInt(s.toString());
                            String c_text = et_c.getText().toString();
                            int c_input = 0;
                            if (!c_text.isEmpty()) {
                                c_input = Integer.parseInt(c_text);
                            }
                            et_b.setText((c_input-a_input)+"");
                        }
                    }
                } catch (Exception exception) {
                    Log.e("Err", exception.toString() + "");
                }
            }
        }
    });
    et_b.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        public void beforeTextChanged(CharSequence s, int start, int count,int after) {
            if(whereFocusing.equals("b")){
                whereChanging = "b";
            }
        }

        public void afterTextChanged(Editable s) {


            try{
                if(whereChanging.equals("b")) {
                    Log.e("Typing", "B is typing....");
                    if(s.length()>0) {
                        int b_input = Integer.parseInt(s.toString());
                        String a_text = et_a.getText().toString();
                        int a_input = 0;
                        if (!a_text.isEmpty()) {
                            a_input = Integer.parseInt(a_text);
                        }
                        et_c.setText((a_input + b_input)+"");
                    }
                }
            }catch(Exception exception){
                Log.e("Err", exception.toString()+"");
            }

        }
    });
    et_c.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        public void beforeTextChanged(CharSequence s, int start, int count,int after) {
            if(whereFocusing.equals("c")){
                whereChanging = "c";
            }
        }

        public void afterTextChanged(Editable s) {

            try{
                if(whereChanging.equals("c")) {
                    Log.e("Typing", "C is typing....");
                    if(s.length()>0) {
                        int c_input = Integer.parseInt(s.toString());
                        String a_text = et_a.getText().toString();
                        int a_input = 0;
                        if (!a_text.isEmpty()) {
                            a_input = Integer.parseInt(a_text);
                        }
                        et_b.setText((c_input-a_input)+"");
                    }
                }
            }catch(Exception exception){
                Log.e("Err", exception.toString()+"");
            }

        }
    });
 }
}

I try as your crazy idea and it works file..... I hope it will help you... Thanks for you idea...I enjoy it :)