• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Displaying Some Text

I have an app that has an EditText box and an "Ok" button.
When they click Ok, the text shows up, but on a new page. I wanted to see it below the ok button. Here is the code:
Code:
public class App2 extends Activity {
    
       /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
        final EditText textname = (EditText) findViewById(R.id.EditText01);
        Button btn1 = (Button)findViewById(R.id.Button01);
     
        // Get Text on Button Press
        btn1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v)
        {         
               String str = textname.getText().toString();
               TextView tv = new TextView(getApplicationContext());
               tv.setText(str);
               setContentView(tv);
        }
        });
    }
}
 
It's so gratifying when you solve your own problems (and you learn AND remember it) LOL. When I thought about it, I didn't have a place to put the data that i entered....simple solution follows: :-)

Code:
        public void onClick(View v)
           {       
               String str = textname.getText().toString();
               TextView tv = (TextView) findViewById(R.id.TextView01);
               tv.setText(str);
           }
 
Back
Top Bottom