Android:没有将spinner的值变为edittext

时间:2013-02-18 09:23:49

标签: android spinner

我有EditTextSpinner的dailog,我正在实施如下

spinner1 = (Spinner) dialog.findViewById(R.id.quesspinner);

ArrayAdapter<CharSequence> arrayadapter = ArrayAdapter.createFromResource(activity, R.array.fbquestion,R.layout.textview);

spinner1.setAdapter(arrayadapter); 


logo.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            spinner1.setVisibility(View.GONE);
            spinner1.performClick();
        }
});

现在我无法读取Spinner的值,我希望Spinner中的文字显示在我的EditText中。代码似乎对我来说没问题,但它没有工作。感谢任何帮助

spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> parent,
            View view, int pos, long id) {
         int Text = parent.getSelectedItemPosition();
           edittext.setText(Text);
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }


    });

2 个答案:

答案 0 :(得分:0)

使用spinner.getSelectedItem()代替parent.getSelectedItem()

答案 1 :(得分:0)

将您的代码更改为

要在更改微调器之前在EditText中显示内容,请执行以下操作

spinner1.setAdapter(arrayadapter); 
edittext.setText(spinner1.getSelectedItem().toString());

spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent,
        View view, int pos, long id) {
     String Text = spinner1.getSelectedItem().toString();
     edittext.setText(Text);
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}


});