0

我有 aEditText和 a 的dailog Spinner,我正在实施如下

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

    }


    });
4

2 回答 2

0

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

于 2013-02-18T09:26:19.070 回答
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

}


});
于 2013-02-18T09:27:01.060 回答