0

I thought making thing part of the app would be easy, however I was wrong. I wish to have a textView display whatever the user wrote in the editText. This is what I tried.

add.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub myTextView.setText(myEditText.getText().toString()); // of course I would use variables in place of the // myTextView and myEditText } }); 

This is another way I tried to get this done.

add.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub //num1 is my String variable num1 = myEditText.getText().toString(); myTextView.setText(num1); } }); 

Both times the textView comes up with nothing in it. Thank you for any help!

1
  • I guess you are instantiate the EditText component. What code you have used to get references of TextView and EditText? Commented Mar 28, 2012 at 1:18

6 Answers 6

1

onClickListener merely responds to user clicks. You need to implement a TextWatcher on your EditText. The most straightforward way of doing this is to implement TextWatcher in your class, then make a call to myEditText.addTextChangedListener(this).

I recommend adding something like the following to your onTextChanged method:

@Override public void onTextChanged(CharSequence s, int start, int before, int count) { myTextView.setText(myTextView.getText()+s);//or something like this... } 
Sign up to request clarification or add additional context in comments.

Comments

1

I usually use GetDlgItemText.

char Buffer[120]; GetDlgItemText(hwndDlg, (control), buffer, sizeof(buffer)); 

This will read it and store it in buffer.

Comments

0

In the EditText the getText call should you return the String, I don't believe you need to call the ToString method on it. The way you are using it in the onClickListener implies you have a button that should be calling a function to set the text into the textview. If you want it dynamically you should be able to use onTextChanged to fill in the data.

Comments

0

First of all check whether the control is coming to your setOnClickListener(). Put in a Log to find that out.

Next make sure that "add" is the button or item that u r using to initiate the copy process.

This statement of yours is correct.

myTextView.setText(myEditText.getText().toString()); 

Though you do not require the toString(). Doesnt really make a difference. I suggest you check that your textview and edittext is fine.

Comments

0

have you check the visibility of textview ?before clicking add button it is invisible rite?then u have to set the visibility on add button click.

Comments

0

From your code i understood that there is a button here too so try this should work:

public class Activity1 extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn = (Button)findViewById(R.id.mybutton); btn.setOnClickListener(btncall); } private OnClickListener btncall = new OnClickListener() { public void onClick(View v) { TextView mytextView = (TextView) findViewById(R.id.MytextView); EditText myeditText = (EditText) findViewById(R.id.MyeditText); mytextView.setText(myeditText.getText().toString()); } }; 

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.