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 :)