Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何像在RecyclerView中一样为微调器创建自定义ViewHolder?_Android_Xml_Android Arrayadapter_Android Spinner_Custom Arrayadapter - Fatal编程技术网

Android 如何像在RecyclerView中一样为微调器创建自定义ViewHolder?

Android 如何像在RecyclerView中一样为微调器创建自定义ViewHolder?,android,xml,android-arrayadapter,android-spinner,custom-arrayadapter,Android,Xml,Android Arrayadapter,Android Spinner,Custom Arrayadapter,我想创建以下类似布局微调器的功能- 我目前拥有的- 我的密码- private MiniProductModel selected产品; 私有地图selectedProductAttributesMap; . . . . @凌驾 public void setProductPurchaseAttributes(){ selectedProductAttributesMap=selectedProduct.getAttributesList(); int启动指数=6; 如果(!isProduc

我想创建以下类似布局微调器的功能-

我目前拥有的-

我的密码-

private MiniProductModel selected产品;
私有地图selectedProductAttributesMap;
.
.
.
.
@凌驾
public void setProductPurchaseAttributes(){
selectedProductAttributesMap=selectedProduct.getAttributesList();
int启动指数=6;
如果(!isProductAvailable)返回;
对于(Map.Entry:selectedProductAttributesMap.entrySet()){
//创建线性布局
LinearLayout LinearLayout=新的LinearLayout(本);
linearLayout.setOrientation(linearLayout.HORIZONTAL);
//创建布局参数
LinearLayout.LayoutParams params=新的LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容);
参数设置边距(25,30,25,0);
linearLayout.setLayoutParams(参数);
//创建文本视图
TextView TextView=新的TextView(此);
textView.setText(entry.getKey().concat(“:”);
textView.setLayoutParams(参数);
//创建微调器
微调器微调器=新微调器(此);
spinner.setLayoutParams(参数);
ArrayAdapter=new ArrayAdapter(getApplicationContext(),android.R.layout.simple_微调器_下拉列表_项,entry.getValue());
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
旋转器。设置适配器(适配器);
//添加到线性布局中
linearLayout.addView(文本视图);
linearLayout.addView(微调器);
//向根视图添加线性布局
productDetailsViewGroup.addView(线性布局,起始索引);
startingIndex++;
}
}
我使用的是默认的数组适配器,它为我提供了一个仅包含TextView的ViewHolder列表

我期待有能力编辑每个持有人,因为我想,所以我可以显示像在易趣图片


考虑到我的代码,我如何才能做到这一点

您需要为类使用自定义数组适配器:

public class SpinnerArrayAdapter extends ArrayAdapter<Spinnermodelwithimage>
{
    int groupid;
    public View v;
    public List<Spinnermodelwithimage> list ;
    Context _activity;
    LayoutInflater inflator;

    public SpinnerArrayAdapter(@NonNull Context context, @LayoutRes int resource, @IdRes int textViewResourceId, @NonNull List <Spinnermodelwithimage>list) {
        super(context, resource, textViewResourceId, list);
        this._activity=context;
        this.list=list;
        this.inflator=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.groupid=resource;
    }

    public View getView1(int position, View convertView, ViewGroup parent ){
        View itemView=inflator.inflate(groupid,parent,false);
        ImageView imageView=(ImageView)itemView.findViewById(R.id.imagespinnertribe);
        TextView textView=(TextView)itemView.findViewById(R.id.company);
        if (list.get(position).getImagepath().isEmpty())
        {
            imageView.setVisibility(View.GONE);

        }

        else {
            imageView.setVisibility(View.VISIBLE);
            Glide.with(_activity).load(list.get(position).getImagepath()).into(imageView);
        }

        textView.setText(list.get(position).getName());
        return itemView;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup parent){
        this.v = convertView;
        if(v==null) {
            LayoutInflater vi = (LayoutInflater)_activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v=vi.inflate(R.layout.spinner_item, null);
        }



        return v;
    }
    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        return getView1(position,convertView,parent);
    }

}
`
微调器\u项目\u新建

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:gravity="center_vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:layout_width="50dp"
            android:visibility="gone"
            android:src="@drawable/logo"
            android:id="@+id/imagespinnertribe"
            android:layout_height="50dp"
            />
        <TextView
            android:id="@+id/company"
            android:visibility="gone"
            android:layout_toRightOf="@+id/imagespinnertribe"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"

            android:layout_marginTop="2dip"
            android:gravity="bottom"
            android:textSize="15dp"

            android:padding="3dip"

            android:textColor="@color/black"
            />
    </RelativeLayout>

    <ImageView
        android:layout_width="match_parent"
        android:background="@color/black"
        android:id="@+id/imageLine"
        android:visibility="gone"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_height="1dp" />

</LinearLayout>

你需要使用
ArrayAdapter
来实现@NileshRathod,我知道。我想知道如何实现我的自定义阵列适配器。我不熟悉它。看起来这是一个很酷的解决方案,但我缺少带有图像的喷丝头模型。您能添加实现吗?我还认为我缺少XML部分。请编辑,以便我可以看到整个图片并完全理解。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:gravity="center_vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:layout_width="50dp"
            android:visibility="gone"
            android:src="@drawable/logo"
            android:id="@+id/imagespinnertribe"
            android:layout_height="50dp"
            />
        <TextView
            android:id="@+id/company"
            android:visibility="gone"
            android:layout_toRightOf="@+id/imagespinnertribe"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_width="match_parent"
            android:layout_height="40dp"

            android:layout_marginTop="2dip"
            android:gravity="bottom"
            android:textSize="15dp"

            android:padding="3dip"

            android:textColor="@color/black"
            />
    </RelativeLayout>

    <ImageView
        android:layout_width="match_parent"
        android:background="@color/black"
        android:id="@+id/imageLine"
        android:visibility="gone"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_height="1dp" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    >

    <TextView
        android:layout_width="match_parent"
        android:textSize="15sp"
        android:paddingLeft="5dp"
        android:visibility="invisible"
        android:id="@+id/textspinner"
        android:gravity="bottom"
        android:textColor="@color/black"
        android:padding="5dip"
        android:layout_height="50dp" />
</LinearLayout>
adapter=new SpinnerArrayAdapter(getContext(),R.layout.spinner_item_new,R.id.company,listspinnerwithimage);
        mspinner.setAdapter(adapter);