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 = new Intent(this, Simple.class);
t.putExtra("editText", text);
startActivity(t);
Then in your Show class' start() method, use:
Intent t = getIntent();
Bundle data = 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:
public class Intents extends Activity {
/** Called when the activity is first created. */
EditText edit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.start);
button.setOnClickListener(mStartListener);
Button button1 = (Button) findViewById(R.id.start1);
button1.setOnClickListener(activity2);
edit=(EditText)findViewById(R.id.edit);
Button show=(Button)findViewById(R.id.show);
show.setOnClickListener(activity3);
}
private OnClickListener mStartListener = new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Intents.this,
startactivity1.class));
}
};
private OnClickListener activity2 = new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(Intents.this,
startactivity2.class));
}
};
private OnClickListener activity3 = new OnClickListener() {
public void onClick(View v) {
String text=edit.getText().toString();
Intent t = new Intent(Intents.this, startactivity3.class);
t.putExtra("editText", text);
startActivity(t);
//startActivity(new Intent(Intents.this,
// startactivity3.class));
}
};
}
public class startactivity3 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actv3);
// Button ok = (Button)findViewById(R.id.but);
TextView text1=(TextView)findViewById(R.id.vi);
Intent t = getIntent();
Bundle data = 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"