Skip to content Skip to sidebar Skip to footer

Android-how To Make The Text Display

I am new To android.I have Some Code..I have Simple.java : public class Simple extends Activity { /** Called when the activity is first created. */ Button show;

Solution 1:

Try adding this to show():

Intent t = newIntent(this, Simple.class);
t.putExtra("editText", text);
startActivity(t);

Then in your Show class' start() method, use:

Intentt= getIntent();
Bundledata= t.getExtras();
text1.setText(data.getString("editText"));

I have not tested this (and am slightly confused by your implementation...) but the putExtra and getExtra functions are what you will likely wish to use.

Solution 2:

publicclassIntentsextendsActivity {
    /** Called when the activity is first created. */

    EditText edit;
    @OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Buttonbutton= (Button) findViewById(R.id.start);
        button.setOnClickListener(mStartListener);
        Buttonbutton1= (Button) findViewById(R.id.start1);
        button1.setOnClickListener(activity2);
        edit=(EditText)findViewById(R.id.edit);
        Button show=(Button)findViewById(R.id.show);
        show.setOnClickListener(activity3);

    }
    privateOnClickListenermStartListener=newOnClickListener() {
        publicvoidonClick(View v) {
            startActivity(newIntent(Intents.this, 
                    startactivity1.class));

        }
    };
    privateOnClickListeneractivity2=newOnClickListener() {
        publicvoidonClick(View v) {
            startActivity(newIntent(Intents.this, 
                    startactivity2.class));        
        }
    };

    privateOnClickListeneractivity3=newOnClickListener() {
        publicvoidonClick(View v) {
            String text=edit.getText().toString();
            Intentt=newIntent(Intents.this, startactivity3.class);
            t.putExtra("editText", text);
            startActivity(t);

            //startActivity(new Intent(Intents.this, //  startactivity3.class));        
        }
    };
}





publicclassstartactivity3extendsActivity {
    publicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.actv3);
     //   Button ok = (Button)findViewById(R.id.but);
        TextView text1=(TextView)findViewById(R.id.vi);
        Intentt= getIntent();
        Bundledata= t.getExtras();
        text1.setText(data.getString("editText"));

    }   

}

Don't forget to add your new activity in android manifest file. go to your current application file click Application and add your new activity in my case i will add showactivity3 in your case you have to activity Show in your manifest. Try this code its tested

Post a Comment for "Android-how To Make The Text Display"