Android 我能否有效地为微调器和listview使用一种布局?

Android 我能否有效地为微调器和listview使用一种布局?,android,listview,android-spinner,android-cursoradapter,Android,Listview,Android Spinner,Android Cursoradapter,我的问题是,与其重新发明传闻的轮子,不如重新发明传闻的轮子我希望对微调器和列表视图使用相同的布局,列表将基于相同的数据。 我还希望在整个应用程序中具有类似的自定义外观,例如列表(微调器和列表视图),具有交替的行颜色和根据当前核心活动编码的颜色() 比如说。我的应用程序中的商店(核心活动)以列表形式出现在列表视图中(ShopName、ShopCity和ShopOrder),用于此的布局为R.layout.shoplist,如下所示: 我的应用程序也有过道(另一个核心活动,因此颜色不同)。过道列表

我的问题是,与其重新发明传闻的轮子,不如重新发明传闻的轮子我希望对微调器和列表视图使用相同的布局,列表将基于相同的数据。

我还希望在整个应用程序中具有类似的自定义外观,例如列表(微调器和列表视图),具有交替的行颜色和根据当前核心活动编码的颜色()

比如说。我的应用程序中的商店(核心活动)以列表形式出现在
列表视图中(ShopName、ShopCity和ShopOrder),用于此的布局为
R.layout.shoplist
,如下所示:

我的应用程序也有过道(另一个核心活动,因此颜色不同)。过道列表仅限于其中一个店铺,因此合并了一个微调器,列出可用店铺以选择相应的过道。如果没有微调器,过道列表当前看起来像:-

我知道,我只需按照使用ShopLIst适配器即可为微调器适配器中的微调器指定ShopLIst Listview的项目布局(其中SCLCRS是包含所有店铺的cusror,而selectshoplist是微调器):-

注意!与标准适配器相比,有3个额外参数,传递
Intent
(提取一个
int
,用于确定使用的颜色范围,第一个
boolean
是一个标志,用于指示来自
微调器的调用,而不是
列表视图
,第二个用于指示是否显示额外数据)

然而,结果是:-

这就是微调器下拉列表中缺少的定制

因此,问题现在可以是我需要做什么来设置下拉列表的背景色

注:我有一个类(ActionColorCodeding)和方法,用于在adpater的
getView
方法中定义/应用颜色,如下所示:-

        int evenrow = ActionColorCoding.setHeadingColor(ctxt,
                callerintent,
                ActionColorCoding.getColorsPerGroup() - 1
                ) & ActionColorCoding.transparency_evenrow;
        int oddrow = evenrow & ActionColorCoding.transparency_oddrow;
        if (position % 2 == 0) {
            view.setBackgroundColor(evenrow);
        } else {
            view.setBackgroundColor(oddrow);
        }
AdapterShopList(Context context,Cursor csr, int flags, Intent intent, boolean fromspinner,boolean showdetails) {
        super(context, csr, 0);
        ctxt = context;
        callerintent = intent;
        this.fromspinner = fromspinner;
        this.cursor = csr;
        setShopOffsets(csr);
    }
因此,上述内容将是纳入适配器的代码的基础。微调器的选择/所选项目的定制不是问题,因为这是根据微调器在活动布局中的声明进行的


注意,这个问题的目的是作为一个指南,可能对其他人的技术有所帮助,因为

微调器实际上有两个与之相关联的布局,第二个布局用于下拉视图,并将调用方法
getDropDown>查看
,如果超出限制(同时ListView调用
getView
方法)

需要注意的一点是,如果调用了
getDropDownView
,则不会调用
bindView
,因此必须调用它

通过向
列表视图
适配器添加以下内容,您的适配器将满足
列表视图
微调器
:-

    @Override
    public View getDropDownView(int position, View convertview, ViewGroup parent) {
        super.getDropDownView(position, convertview, parent);
        View view = convertview;
        if (fromspinner) {
            int cpos = this.cursor.getPosition();
            view = View.inflate(ctxt,R.layout.shoplist,null);
            int evenrow = ActionColorCoding.setHeadingColor(ctxt,callerintent, ActionColorCoding.getColorsPerGroup() - 1) & ActionColorCoding.transparency_evenrow;
            int oddrow = evenrow & ActionColorCoding.transparency_oddrow;
            if (position % 2 == 0) {
                view.setBackgroundColor(evenrow);
            } else {
                view.setBackgroundColor(oddrow);
            }
            this.cursor.moveToPosition(position);
        }
        bindView(view, ctxt, this.cursor);
        return view;
    }
注意!我不认为需要
**if(fromspinner)**
构造,但已作为预防措施包括在内

附加说明,callng
super.getDropDownView(位置、convertview、父项);
似乎不是必需的,因此可能是最好的说明

注意!
ctxt
调用方
来自微调器的
光标
根据以下内容在Adpater的构造函数中设置:-

        int evenrow = ActionColorCoding.setHeadingColor(ctxt,
                callerintent,
                ActionColorCoding.getColorsPerGroup() - 1
                ) & ActionColorCoding.transparency_evenrow;
        int oddrow = evenrow & ActionColorCoding.transparency_oddrow;
        if (position % 2 == 0) {
            view.setBackgroundColor(evenrow);
        } else {
            view.setBackgroundColor(oddrow);
        }
AdapterShopList(Context context,Cursor csr, int flags, Intent intent, boolean fromspinner,boolean showdetails) {
        super(context, csr, 0);
        ctxt = context;
        callerintent = intent;
        this.fromspinner = fromspinner;
        this.cursor = csr;
        setShopOffsets(csr);
    }
结果是:-


给别人几分钟时间回复:)@MehdiKhademloo,如底部的注释所示。答案是众所周知的。该问题已作为其他人的指南提供。因此,在提问时可以使用AskandAnswer选项。添加了一个额外的注释,重新调用
super。getDropDownView
是多余的。