我为 Spinner
创建了一个自定义 ArrayAdapter
。不同之处在于,它显示来自复杂类的 ArrayList
的图像,而不是纯文本。到目前为止它有效。图像和单选按钮按需要显示。问题是,下拉 View 的行为不正确:它不会在单击时关闭,并且只有单选按钮是可单击的,而不是整个 View 。
有人知道哪里出了问题吗?我必须在 adapter
中实现某种类型的 listener
吗??
这是 getDropDownView
方法的代码:
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout view=(LinearLayout)inflater.inflate(R.layout.spinnerimageitem, null);
ImageView iv=(ImageView)view.getChildAt(0);
RadioButton rb=(RadioButton)view.getChildAt(1);
int iImageID=ctx.getResources().getIdentifier(
"f_"+funcs.get(position).getBitmapSetup(),
"drawable", ctx.getPackageName());
if(loco.getFunction(iIndex).equals(funcs.get(position)))
rb.setChecked(true);
iv.setImageResource(iImageID);
return(view);
}
最佳答案
在单选按钮的布局中设置 android:focusable="false"
。
关于android - 微调器的自定义 ArrayAdapter : drop down view not working properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15000120/