I have three EditText, I want to concatinate the strings present in the first two EditText fields,and display in the third EditText field.After entering the string at 2nd field,it automatically concatinate and set in the third EditText.
EditText text1 = (EditText) findViewById(R.id.text1);
mtext1=text1.getText.toString();
EditText text2 = (EditText) findViewById(R.id.text2);
mtext2 = text2.getText.toString();
mtext3=mtext1.concat().mtext2;
Edit text3 = (EditText) findViewById(R.id.text3);
text3 = setText(mtext3.toString());
I wrote the above code.But I result is not shomn in the third EditText. Please give the solution, that I implement in my program
This example demonstrates how do I set only numeric value for editText in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
In android, EditText is a user interface control which is used to allow the user to enter or modify the text. While using EditText control in our android applications, we need to specify the type of data the text field can accept using the inputType attribute.
This should work. Make sure you do not edit text2 in the TextChanged listener because then afterTextChanged would get called again.
final EditText text1 = (EditText) findViewById(R.id.text1);
final EditText text2 = (EditText) findViewById(R.id.text2);
final EditText text3 = (EditText) findViewById(R.id.text3);
text2.addTextChangedListener(new TextWatcher() {
void afterTextChanged(Editable s) {
text3.setText(text1.getText().toString() + text2.getText().toString());
};
});
If you want to detect when your two EditText fields change, you're going to need to use addTextChangedListener() on each of them. The following can go in your onCreate() method:
final EditText text1 = (EditText) findViewById(R.id.text1);
final EditText text2 = (EditText) findViewById(R.id.text2);
final EditText text3 = (EditText) findViewById(R.id.text3);
TextWatcher watcher = new TextWatcher() {
void afterTextChanged(Editable s) {
text3.setText(text1.getText() + text2.getText());
};
});
text1.addTextChangedListener(watcher);
text2.addTextChangedListener(watcher);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With