【发布时间】:2011-05-31 04:06:12
【问题描述】:
我正在开发一个 android 应用程序,其中我有两个按钮和一个编辑文本框。 我想通过单击其中一个按钮将字符串中的编辑文本框的数据传递给下一个活动,我如何将文本传递给下一个活动并在新启动的活动中接收该文本,以便可以使用该文本在那里面。
我的第一个活动代码是
EditText Urlis=(EditText)findViewById(R.id.entry);
final Button button = (Button) findViewById(R.id.ok);
final Intent i=new Intent(this , RSSReder.class);
final String choice=Urlis.getText().toString();
i.putExtra("key", choice);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(i);
}
});
对于被调用的活动是
public class RSSReder extends Activity implements OnItemClickListener {
public String RSSFEEDOFCHOICE;
public final String tag = "RSSReader";
private RSSFed feed = null;
/** Called when the activity is first created. */
public void onCreate(Bundle abc) {
super.onCreate(abc);
setContentView(R.layout.next1);
Intent i = getIntent();
RSSFEEDOFCHOICE =i.getStringExtra("key");
// go get our feed!
feed = getFeed(RSSFEEDOFCHOICE);
// display UI
UpdateDisplay();
}
}
有什么我需要更改或删除的。
【问题讨论】:
-
尝试输入“String choice=Urlis.getText().toString();”在“onClick()”方法中。还要放“i.putExtra("key",choice);"在“onClick()”之后。目前在哪里获得文本,很可能您将“选择”设置为空白字符串。当用户按下 Button 启动新 Activity 时,您需要获取文本。
-
谢谢先生,我的代码应用程序正在运行,真的很有帮助
标签: android string button android-activity