Android的如何使文本显示 [英] Android-How To Make the Text display
问题描述
我是新来android.I有一些code..I有
I am new To android.I have Some Code..I have
Simple.java:
Simple.java :
public class Simple extends Activity {
/** Called when the activity is first created. */
Button show;
TextView view;
EditText edit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
show=(Button)findViewById(R.id.show);
view=(TextView)findViewById(R.id.view);
edit=(EditText)findViewById(R.id.edit);
show.setOnClickListener(new OnClickListener(){
public void onClick(View view){
show();
}
});
}
public void show(){
String text=edit.getText().toString();
view.setText(text);
Intent t=new Intent(this,Show.class);
startActivity(t);
}
}
当我试图以显示它的工作原理相同的活动的文字...
我想通过我输入了的EditText,并把它显示给Show.class文本
When i tried To Display the text in the same activity it works... I am trying to pass the text Which i typed in EditText and to display it to Show.class
在code为Show.class
the code for Show.class
公共类展会扩展活动{
private Simple simple;
TextView text1;
Button back;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
back=(Button)findViewById(R.id.button);
text1=(TextView)findViewById(R.id.then);
back.setOnClickListener(new OnClickListener(){
public void onClick(View view){
start();
}
});
}
public void start(){
String t=simple.edit.getText().toString();
text1.setText(t);
Intent t=new Intent(this,Simple.class);
startActivity(t);
}
}
我想这一次我不能够显示这是我给的EDITTEXT在Simple.java的文本。
我知道这是基本的,但我知道。所以,请帮我out.Thanks提前..
I tried this one I am not able to Display the text which i gave in editText in Simple.java. I know it is basic but I do know. So Please Help me out.Thanks in Advance..
推荐答案
尝试添加这表明():
Intent t = new Intent(this, Simple.class);
t.putExtra("editText", text);
startActivity(t);
然后在您的显示类的start()方法,使用:
Then in your Show class' start() method, use:
Intent t = getIntent();
Bundle data = t.getExtras();
text1.setText(data.getString("editText"));
我没有测试过这一点(您实现......我稍微混淆),但putExtra和getExtra功能是什么,你可能会希望使用。
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.
这篇关于Android的如何使文本显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!