我创建了三个具有特定值列表的 Spinners。我将每个 Spinner 的选择值存储在一个变量中。问题是当我转到下一页时,我丢失了我的变量。我该怎么办?
public class TabOneActivity extends Activity implements OnItemSelectedListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabone);
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.fudtaste);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add(" Chineese");
categories.add(" Fast Food");
categories.add(" Traditional");
categories.add(" Mixed");
categories.add(" Favourites");
categories.add(" Combo Items");
//Toast.makeText(getApplicationContext(),newPos1,Toast.LENGTH_LONG).show();
// System.out.println(str + "sarath" );
Spinner spinner2 = (Spinner) findViewById(R.id.foodmoney);
// Spinner click listener
spinner2.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories2 = new ArrayList<String>();
categories2.add(" Fast Food");
categories2.add(" Pub Food");
categories2.add(" High End Food");
// categories2.add(" ");
// categories2.add(" Music With Food");
// categories2.add(" Enjoy The Food");
int newPos2 = spinner2.getSelectedItemPosition();
//Toast.makeText(getApplicationContext(),newPos2,Toast.LENGTH_LONG).show();
System.out.println(newPos2 + "sarath" );
Spinner spinner3 = (Spinner) findViewById(R.id.transport);
// Spinner click listener
spinner3.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories3 = new ArrayList<String>();
categories3.add(" I'll Walk");
categories3.add(" A Cab Please");
categories3.add(" Limo!!");
int newPos3 = spinner3.getSelectedItemPosition();
//Toast.makeText(getApplicationContext(),newPos3,Toast.LENGTH_LONG).show();
System.out.println(newPos3 + "sarath" );
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories2);
ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories3);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
spinner2.setAdapter(dataAdapter2);
spinner3.setAdapter(dataAdapter3);
Button bt1 = (Button)findViewById(R.id.search1);
bt1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent j = new Intent(getApplicationContext(), PlanMyDayListActivity.class);
j.putExtra("tab", 1);
startActivity(j);
}
});
}
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// // On selecting a spinner item
// String item = parent.getItemAtPosition(position).toString();
//
//// Context mContext = null;
//// Toast.makeText(mContext,item,Toast.LENGTH_SHORT).show();
// Toast.makeText(getApplicationContext(),item,Toast.LENGTH_LONG).show();
//
// }
public void onNothingSelected(AdapterView<?> arg0) {
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
}