如何自定义微调下拉列表视图 [英] How to customize the Spinner dropdown view

查看:129
本文介绍了如何自定义微调下拉列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以定制微调下拉列表视图。默认微调下拉观点有适配器视图。我想改变这种看法有自己的文本视图或一些像这样的事情。

Is it possible to customize the spinner drop-down view . Default spinner drop-down view has adapter view . I want change that view to have my own text view or some thing like this.

推荐答案

添加这个内部类在你的类并修改它,请你。

Add this inner class in your class and modify it as you please.

public class MyAdapter extends ArrayAdapter<String>{

        public MyAdapter(Context context, int textViewResourceId,   String[] objects) {
            super(context, textViewResourceId, objects);
        }

        @Override
        public View getDropDownView(int position, View convertView,ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }

        public View getCustomView(int position, View convertView, ViewGroup parent) {

            LayoutInflater inflater=getLayoutInflater();
            View row=inflater.inflate(R.xml.row, parent, false);
            TextView label=(TextView)row.findViewById(R.id.company);
            label.setText(strings[position]);

            TextView sub=(TextView)row.findViewById(R.id.sub);
            sub.setText(subs[position]);

            ImageView icon=(ImageView)row.findViewById(R.id.image);
            icon.setImageResource(arr_images[position]);

            return row;
            }
        }

和此适配器添加到您的微调:

And add this adapter to your spinner:

    Spinner mySpinner = (Spinner)findViewById(R.id.expandableImagesList);
    mySpinner.setAdapter(new MyAdapter(NewEventActivity.this, R.xml.row, strings));

,也可以创建一个新的XML,并添加所有的事情,你希望你的微调包含:

And also create a new xml and add all the things you want your spinner to contain:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:padding="3dip"
>
    <ImageView
         android:id="@+id/image"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/icon"/>
    <TextView
         android:layout_toRightOf="@+id/image"
         android:padding="3dip"
         android:layout_marginTop="2dip"
         android:textStyle="bold"
         android:id="@+id/company"
         android:text="CoderzHeaven"
         android:layout_marginLeft="5dip"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
     <TextView
         android:layout_toRightOf="@+id/image"
         android:padding="2dip"
         android:layout_marginLeft="5dip"
         android:id="@+id/sub"
         android:layout_below="@+id/company"
         android:text="Heaven of all working codes"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
</RelativeLayout>

这是我的code,所以你必须改变它为您的需求。

This is my code so you have to change it for your needs

这篇关于如何自定义微调下拉列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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