我有4 Spinners
和1 Button
在Activity A
。我正在使用該Button
打開另一個Activity B
。現在我想在Activity B
中顯示選定的Spinners
信息。我知道如何通過EditText
的數據,但我不知道Spinners
。將微調器信息傳遞給另一個活動
請幫我從另一個Activity
public class MainActivity extends ActionBarActivity {
private Button btn;
private Spinner spin1;
private Spinner spin2;
private Spinner spin3;
private Spinner spin4;
public class SpinnersData implements Serializable
{
private String spinner1;
private String spinner2;
private String spinner3;
private String spinner4;
public String getSpinner1()
{
return spinner1;
}
public void setSpinner1(String spinner1)
{
this.spinner1 = spinner1;
}
public String getSpinner2()
{
return spinner2;
}
public void setSpinner2(String spinner2)
{
this.spinner2 = spinner2;
}
public String getSpinner3()
{
return spinner3;
}
public void setSpinner3(String spinner3)
{
this.spinner3 = spinner3;
}
public String getSpinner4()
{
return spinner4;
}
public void setSpinner4(String spinner10)
{
this.spinner4 = spinner4;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn= (Button)findViewById(R.id.button1);
spin1=(Spinner)findViewById(R.id.spinner1);
final String arr1[] = {"NONE"," 1*£5.49","2*2.00","3*4.00"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_dropdown_item_1line, arr1);
spin1.setAdapter(adapter);
spin1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "the item selected "+arr1[arg2],Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
//TODO Auto-generated method stub
}
});
spin1=(Spinner)findViewById(R.id.spinner1);
final String arr2[] = {"NONE"," 1*£5.49","2*2.00","3*4.00"};
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_dropdown_item_1line, arr2);
spin2.setAdapter(adapter);
spin2.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "the item selected "+arr2[arg2],Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
//TODO Auto-generated method stub
}
});
spin3=(Spinner)findViewById(R.id.spinner1);
final String arr3[] = {"NONE"," 1*£5.49","2*2.00","3*4.00"};
ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_dropdown_item_1line, arr3);
spin3.setAdapter(adapter);
spin3.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "the item selected "+arr3[arg2],Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
//TODO Auto-generated method stub
}
});
spin4=(Spinner)findViewById(R.id.spinner1);
final String arr4[] = {"NONE"," 1*£5.49","2*2.00","3*4.00"};
ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_dropdown_item_1line, arr4);
spin4.setAdapter(adapter);
spin4.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "the item selected "+arr4[arg2],Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
//TODO Auto-generated method stub
}
});
btn= (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent inte = new Intent (MainActivity.this, Finalorder.class);
SpinnersData data = new SpinnersData();
data.setSpinner1(spin1.getSelectedItem().toString());
data.setSpinner2(spin2.getSelectedItem().toString());
data.setSpinner3(spin3.getSelectedItem().toString());
data.setSpinner4(spin4.getSelectedItem().toString());
inte.putExtra("SPINNERVAL", data);
startActivity(inte);
}
});
}}
收到Spinners
信息下面是第二Activity
,我想收到Spinners
信息。我不知道我在哪裏寫錯了代碼。請
活動2
public class Finalorder extends MainActivity {
Bundle Bundle;
TextView txt;
Button btn;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.last);
Bundle=getIntent().getExtras();
SpinnersData data = (SpinnersData) getIntent().getExtras().getSerializable("SPINNERVAL");
}}
問題是什麼? – Blundell 2014-10-28 22:01:38
隨機猜測:使'SpinnersData'類'靜態' – Blundell 2014-10-28 22:02:25
我嘗試從藍色堆棧應用程序播放器。它沒有在那開放。我不知道我的代碼有什麼錯誤 – sudheir 2014-10-28 22:13:58