如何在doInBackground中传递微调器的值

时间:2018-01-20 18:25:20

标签: android android-asynctask android-spinner

我想在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。请帮帮我,谢谢你。

0 个答案:

没有答案