重新分配微调器值的问题

时间:2011-05-31 19:53:27

标签: android android-widget

我试图从微调器中获取一个值,然后将其传递给另一个java文件。我有一个微调器,其中有许多值。我更改了这个值,将其转换为字符串,然后单击我使用的按钮,并意图将此信息传递到其他java文件中以执行操作。

我遇到的问题是,一旦我最初设置微调器值,即使我更改了微调器,传递的值也不会改变。

即使我更改了微调器,传递给LiquidFlowResults的位置值仍然可能是最初分配的= 0。

/** initially setting spinner value */
int possize = 0;
String pipeSizeString = Integer.toString(possize);

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button calculateButton = (Button) findViewById(R.id.button1);
    calculateButton.setOnClickListener(mEnableListener);


    Spinner spinnerPipeSize = (Spinner) findViewById(R.id.spinnerPipeSize);
    ArrayAdapter<CharSequence> adapterpipesize = ArrayAdapter.createFromResource(this, R.array.pipesize_array, android.R.layout.simple_spinner_item);
    adapterpipesize.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerPipeSize.setAdapter(adapterpipesize);    

    spinnerPipeSize.setOnItemSelectedListener(new PipeSizeOnItemSelectedListener());

/** Listening for spinner position */

public class PipeSizeOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent,
        View view, int possize, long id) {
        String pipeSizeString = Integer.toString(possize);
    }

    public void onNothingSelected(AdapterView<?> parent) {
      // Do nothing.
    }
}

/** passing on information on click of button */

private OnClickListener mEnableListener = new OnClickListener() {

    public void onClick(View view)
    {
        Intent intent = new Intent(LiquidFlow.this, LiquidFlowResults.class);
        Bundle sizeposition = new Bundle();
                sizeposition.putString("pipeSizeStringPositionMoved", pipeSizeString);
                intent.putExtras(sizeposition);
    startActivity(intent);

    }
};

1 个答案:

答案 0 :(得分:0)

不需要PipeSizeOnItemSelectedListener。你可以在OnClickListener中调用getSelectedItemPosition。