我想在AsyncTask中将值从spinner传递给doInBackground。我使用这段代码:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(MainActivity.this, android.R.layout.simple_spinner_item, myArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setSelection(0);
OnItemSelectedListener itemSelectedListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Integer item = (Integer)parent.getItemAtPosition(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
spinner.setOnItemSelectedListener(itemSelectedListener);
public void onClick(View view) {
SomeTask = new SomeTask();
SomeTask.execute();
class SomeTask extends AsyncTask<Void, Integer, Void> {
@Override
protected Void doInBackground (Void...params){
//do something with variable item
}
}
//do all next things
而且我不知道如何将变量项传递给doInBackground。请帮帮我,谢谢你。