0

I use getText(); on an editText using the code below and want the users input to replace a textView then how do I do this?
btw the code was taken from this question:
Get Value of a Edit Text field

Button   mButton;
EditText mEdit;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mButton = (Button)findViewById(R.id.button);
mEdit   = (EditText)findViewById(R.id.edittext);

mButton.setOnClickListener(
    new View.OnClickListener()
    {
        public void onClick(View view)
        {
            Log.v("EditText", mEdit.getText().toString());
        }
    });
}
Community
  • 1
  • 1
john fowles
  • 127
  • 1
  • 6
  • Can you explain a little better what your specific problem is? I don't see an attempt here from what I understand of the question – codeMagic Feb 01 '15 at 08:00
  • do you want to set EditText empty after user click too ? – YFeizi Feb 01 '15 at 08:04
  • Specifically I want one edit text box at the bottom of the page and 6 textViews at the top of the page with variables holding the spots. one textView on top of the editText field at the bottom of page will have 6 questions that show one at a time. So the user will answer the first question and that will replace the variable in one of the textViews and then a second question will appear in the textView above the editText box .... I apologize for my lack of clarity as I am very new to programming. – john fowles Feb 01 '15 at 08:16

3 Answers3

2

1- Find your textView

TextView txt = (TextView) findViewById(R.id.yourTextView);

2- After you get the text from EditText set it to TextView :

txt.setText(mEdit.getText().toString());
YFeizi
  • 1,498
  • 3
  • 28
  • 50
0

I think an array of TextView would be nice in your case.

TextView [] myTexts = new TextView[6];
myTexts[0]=findViewById(R.id.txt1);
myTexts[1]=findViewById(R.id.txt2);
...
myTexts[5]=findViewById(R.id.txt6);

int questionNumber = 0;
mButton.setOnClickListener(
new View.OnClickListener()
{
    public void onClick(View view)
    {
        myTexts[questionNumber].setText(mEdit.getText().toString());
        questionNumber++;
     }
});

questionNumber integer will hold the value of which question is going to be answered but don't let its value to be greater then 5 if you don't want ArrayIndexOutOfRange exception.

Nanites
  • 410
  • 3
  • 16
-1
Button   mButton;
EditText mEdit;
TextView mText;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mButton = (Button)findViewById(R.id.button);
mEdit   = (EditText)findViewById(R.id.edittext);
mText = (TextView) findViewById(R.id.textview1);

mButton.setOnClickListener(
    new View.OnClickListener()
    {
        public void onClick(View view)
        {
            Log.v("EditText", mEdit.getText().toString());
            mText.setText(mEdit.getText.toString());
        }
    });
}
chiru
  • 635
  • 1
  • 7
  • 14