1. Check out our app, Forums for Android! Download and leave feedback here!

Displaying Some Text

Discussion in 'Application Development' started by Rootstonian, Nov 27, 2010.

  1. Rootstonian

    Rootstonian Member
    Thread Starter
    15

    Nov 25, 2010
    16
    0
    15
    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 (Text):
    1.  
    2. public class App2 extends Activity {
    3.    
    4.        /** Called when the activity is first created. */
    5.     @Override
    6.     public void onCreate(Bundle savedInstanceState) {
    7.         super.onCreate(savedInstanceState);
    8.         setContentView(R.layout.main);
    9.      
    10.         final EditText textname = (EditText) findViewById(R.id.EditText01);
    11.         Button btn1 = (Button)findViewById(R.id.Button01);
    12.      
    13.         // Get Text on Button Press
    14.         btn1.setOnClickListener(new View.OnClickListener() {
    15.         public void onClick(View v)
    16.         {        
    17.                String str = textname.getText().toString();
    18.                TextView tv = new TextView(getApplicationContext());
    19.                tv.setText(str);
    20.                setContentView(tv);
    21.         }
    22.         });
    23.     }
    24. }
    25.  
     

    Advertisement

  2. Rootstonian

    Rootstonian Member
    Thread Starter
    15

    Nov 25, 2010
    16
    0
    15
    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 (Text):
    1.  
    2.         public void onClick(View v)
    3.            {      
    4.                String str = textname.getText().toString();
    5.                TextView tv = (TextView) findViewById(R.id.TextView01);
    6.                tv.setText(str);
    7.            }
    8.  
     

Share This Page

Loading...