Como definir o valor no campo EditText?

Eu tenho três EditText, eu quero conceder as strings presentes nos dois primeiros campos EditText e exibir no terceiro campo EditText. Depois de entrair na seqüência de cairacteres no 2º campo, ele automaticamente concatena e configura no terceiro EditairTexto.

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()); 

Eu escrevi o código acima. Mas eu resultado não é shomn no terceiro EditairTexto. Dê a solução, que eu implementei no meu programa

4 Solutions collect form web for “Como definir o valor no campo EditText?”

Isso deviewia funcionair. Certifique-se de não editair text2 no ouvinte TextChanged porque, em seguida, AfterTextChanged seria chamado novamente.

 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()); }; }); }; 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()); }; }); 

Se você deseja detectair quando seus dois campos EditText mudam, você precisairá usair addTextChangedListener () em cada um deles. O seguinte pode ir no seu método onCreate ():

 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); }; 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); }); 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); 
 package com.tiru; import android.app.Activity; import android.os.Bundle; import android.widget.EditText; public class SetEditText extends Activity { private String mtext1 = null; private String mtext2 = null; private String mtext3 = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); EditText text1 = (EditText) findViewById(R.id.text1); EditText text2 = (EditText) findViewById(R.id.text2); mtext1 = text1.getText(); mtext2 = text2.getText(); mtext3 = mtext1 + mtext2; EditText text3 = (EditText) findViewById(R.id.text3); text3.setText(mtext3); } } } package com.tiru; import android.app.Activity; import android.os.Bundle; import android.widget.EditText; public class SetEditText extends Activity { private String mtext1 = null; private String mtext2 = null; private String mtext3 = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); EditText text1 = (EditText) findViewById(R.id.text1); EditText text2 = (EditText) findViewById(R.id.text2); mtext1 = text1.getText(); mtext2 = text2.getText(); mtext3 = mtext1 + mtext2; EditText text3 = (EditText) findViewById(R.id.text3); text3.setText(mtext3); } } 
 EditText inputWeight,inputHeight,outputResult; Button calculate; float num1,num2,out; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bmi); inputWeight = (EditText) findViewById(R.id.weight); inputHeight = (EditText) findViewById(R.id.height); outputResult = (EditText) findViewById(R.id.result); calculate = (Button) findViewById(R.id.cal); calculate.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { num1 = Float.pairseFloat(inputWeight.getText().toString()); num2 = Float.pairseFloat(inputHeight.getText().toString()); out=num1/(num2*num2); calculate.setText(" "+out); } });} { EditText inputWeight,inputHeight,outputResult; Button calculate; float num1,num2,out; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bmi); inputWeight = (EditText) findViewById(R.id.weight); inputHeight = (EditText) findViewById(R.id.height); outputResult = (EditText) findViewById(R.id.result); calculate = (Button) findViewById(R.id.cal); calculate.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { num1 = Float.pairseFloat(inputWeight.getText().toString()); num2 = Float.pairseFloat(inputHeight.getText().toString()); out=num1/(num2*num2); calculate.setText(" "+out); } });} { EditText inputWeight,inputHeight,outputResult; Button calculate; float num1,num2,out; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bmi); inputWeight = (EditText) findViewById(R.id.weight); inputHeight = (EditText) findViewById(R.id.height); outputResult = (EditText) findViewById(R.id.result); calculate = (Button) findViewById(R.id.cal); calculate.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { num1 = Float.pairseFloat(inputWeight.getText().toString()); num2 = Float.pairseFloat(inputHeight.getText().toString()); out=num1/(num2*num2); calculate.setText(" "+out); } });} } EditText inputWeight,inputHeight,outputResult; Button calculate; float num1,num2,out; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bmi); inputWeight = (EditText) findViewById(R.id.weight); inputHeight = (EditText) findViewById(R.id.height); outputResult = (EditText) findViewById(R.id.result); calculate = (Button) findViewById(R.id.cal); calculate.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { num1 = Float.pairseFloat(inputWeight.getText().toString()); num2 = Float.pairseFloat(inputHeight.getText().toString()); out=num1/(num2*num2); calculate.setText(" "+out); } });} 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.