Java 使用微调器在活动之间传输数据
我是Android开发的新手 我正在尝试将所选数据从多个微调器(搜索活动)传输到另一个活动(JSON搜索结果活动) 在最后,我有一个打开搜索结果的按钮Java 使用微调器在活动之间传输数据,java,android,Java,Android,我是Android开发的新手 我正在尝试将所选数据从多个微调器(搜索活动)传输到另一个活动(JSON搜索结果活动) 在最后,我有一个打开搜索结果的按钮 Bundle extras = getIntent().getExtras(); if(extras!=null){ Integer item = extras.getInt("setwhat"); //Use a switch(item) here to switch to diffe
Bundle extras = getIntent().getExtras();
if(extras!=null){
Integer item = extras.getInt("setwhat");
//Use a switch(item) here to switch to different links based on selection
TextView tv = (TextView) findViewById(R.id.tvtv);
tv.setText("Another Activity, Item is :" + item.toString());
搜索活动:
我有java微调器
ArrayAdapter<CharSequence> whatlist = ArrayAdapter.createFromResource(this,
R.array.whatlist, android.R.layout.simple_spinner_item);
whatlist.setDropDownViewResource(R.layout.spinner_style);
spwhat = (Spinner) findViewById(R.id.spWhat);
spwhat.setAdapter(whatlist);
spwhat.setOnItemSelectedListener(new MyOnItemSelectedListener());
这在搜索结果中
Bundle extras = getIntent().getExtras();
if(extras!=null){
Integer item = extras.getInt("setwhat");
//Use a switch(item) here to switch to different links based on selection
TextView tv = (TextView) findViewById(R.id.tvtv);
tv.setText("Another Activity, Item is :" + item.toString());
文本不会改变。
我在网上尝试过任何教程,并在这里搜索了几个小时的解决方案。。
有人可以帮忙吗?您甚至不需要为微调器设置侦听器。只需将按钮的onclick更改为:
btnsearch = (Button)findViewById(R.id.btnSearch);
btnsearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Spinner spwhat = (Spinner) findViewById(R.id.spWhat);
Intent ia = new Intent(SearchActivity.this, SearchResult.class);
ia.putExtra("setwhat", spwhat.getSelectedItem().toString());
startActivity(ia);
}
});
btnsearch = (Button)findViewById(R.id.btnSearch);
btnsearch.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Spinner spwhat = (Spinner) findViewById(R.id.spWhat);
Intent ia = new Intent(SearchActivity.this, SearchResult.class);
ia.putExtra("setwhat", spwhat.getSelectedItem().toString());
startActivity(ia);
}
});