【发布时间】:2015-02-10 20:08:24
【问题描述】:
在第一个活动中,我有一个微调器和一个按钮。我想使其进行操作,以便选择旋转器选项,然后单击按钮时,打开新活动,并在TextView中显示旋转器选项(以及有关IT的其他信息)。简而言之,我正在尝试使用意图来发送和检索数据,然后添加其他信息,我认为我会使用 putExtra() 方法。
这里我有指向第二页的按钮,我试图通过意图存储微调器的对象。
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button yourButton = (Button) findViewById(R.id.done);
yourButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(MainActivity.this, Selected.class);
intent.putExtra("new_variable_name","value");
startActivity(intent);
}
});
这里是 Selected.class(第二个活动) 我想检索微调器信息并将其放入文本视图中。
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("new_variable_name");
}
}
另外,这里是名为“person_array”的微调器数组:
<string-array name="person_array">
<item>Nick</item>
<item>Isaac</item>
<item>Sally</item>
<item>Matt</item>
<item>Tim</item>
</string-array>
【问题讨论】:
标签: android button android-intent android-studio spinner