我有EditText
和Spinner
的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
}
});
答案 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
}
});