Spinner的自定义ArrayAdapter:下拉视图无法正常工作 [英] Custom ArrayAdapter for a Spinner: drop down view not working properly

查看:122
本文介绍了Spinner的自定义ArrayAdapter:下拉视图无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 Spinner 创建了一个自定义的 ArrayAdapter 。不同之处在于,它显示的是来自复杂类的 ArrayList 的图像,而不是纯文本。到目前为止,它仍然有效。根据需要显示图像和单选按钮。问题在于,下拉视图的行为不正确:单击时不会关闭,只能单击单选按钮而不是整个视图。

I created a custom ArrayAdapter for a Spinner. The difference is, that it shows images from an ArrayList of a complex class instead of plain text. It works so far. The Images and the radio buttons are displayed as desired. The problem is, that the drop down view doesn't behave correctly: it doesn't close on a click and only the radio buttons are clickable instead of the whole view.

有人知道有什么问题吗?我必须在适配器 ??

Does anybody has an idea what's wrong? Do I have to implement some kind of listener in the adapter??

这是 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);
    }


推荐答案

set android:focusable = false 。

这篇关于Spinner的自定义ArrayAdapter:下拉视图无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆