-1

I am a Java rookie and need some help with my code.

I am trying to get a variable out of the code below so that I later on can make the numbers that you write in the EditText field display in as a TextView.

The code:

public class MoneyTickerActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final EditText edittext = (EditText) findViewById(R.id.editText1);
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  Toast.makeText(MoneyTickerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                  return true;
                }
                return false;
            }
        });
    }
}
Sufian
  • 6,405
  • 16
  • 66
  • 120
  • Can you provide a more specific question? – slayton Oct 27 '11 at 20:20
  • I want the numbers that the user types in the EditText filed to be displayed as a TextView instead of a toast. Does that make it more clear? Sorry, but have a hard time to describe it because my lack of java knowledge – user1017191 Oct 27 '11 at 20:34
  • see this: http://stackoverflow.com/questions/2300169/how-to-change-text-in-android-textview – slayton Oct 27 '11 at 20:59

1 Answers1

1
// get text view
final TextView texView = (TextView) findViewById(R.id.textView1);

and instead of

Toast.makeText(MoneyTickerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();

make

textView.setText(edittext.getText());
nostra13
  • 12,377
  • 3
  • 33
  • 43