Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.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 仅显示一个对象的自定义ArrayAdapter_Android_Android Arrayadapter_Android Spinner_Custom Arrayadapter - Fatal编程技术网

Android 仅显示一个对象的自定义ArrayAdapter

Android 仅显示一个对象的自定义ArrayAdapter,android,android-arrayadapter,android-spinner,custom-arrayadapter,Android,Android Arrayadapter,Android Spinner,Custom Arrayadapter,我有以下定制阵列适配器- 公共类ColorAttributeArrayAdapter扩展了ArrayAdapter{ 私人名单标题; 私人语境; 私人市场; public colorAttributerRayaAdapter(@NonNull上下文上下文,列表标题){ super(上下文、R.layout.product\u属性\u微调器\u行项目、R.id.product\u属性\u微调器\u行项目\u文本视图、标题); //超级(上下文,0,标题); this.titles=标题; this

我有以下定制阵列适配器-

公共类ColorAttributeArrayAdapter扩展了ArrayAdapter{
私人名单标题;
私人语境;
私人市场;
public colorAttributerRayaAdapter(@NonNull上下文上下文,列表标题){
super(上下文、R.layout.product\u属性\u微调器\u行项目、R.id.product\u属性\u微调器\u行项目\u文本视图、标题);
//超级(上下文,0,标题);
this.titles=标题;
this.context=上下文;
改装改装=新改装.Builder()
.baseUrl(基本门户网站制作URL)
//.baseUrl(基本门户网站阶段URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
marketApiCalls=reformation.create(marketApiCalls.class);
}
@非空
@凌驾
公共视图getView(int位置,@Nullable视图convertView,@NonNull视图组父级){
查看列表项=转换视图;
如果(listItem==null){
listItem=LayoutFlater.from(上下文)。充气(R.layout.product\u attribute\u spinner\u row\u item,父项,false);
}
//String currentString=titles.get(位置).GetAttributeValue().get(位置);
List attributeValues=titles.get(position.getAttributeValues();
对于(int i=0;i
下面是我如何创建适配器-

for(Map.Entry:selectedProductAttributesMap.entrySet()){
//每个迭代的键和值
String key=entry.getKey();
列表值=entry.getValue()
.
.
.
ArrayList productAttributeModels=新的ArrayList();
添加(新的ProductAttributeModel(键,值));
ColorAttributeArrayaAdapter=新的ColorAttributeArrayaAdapter(此为productAttributeModels);
spinner.setOnItemSelectedListener(此);
旋转器。设置适配器(适配器);
}
我的模型-

公共类ProductAttributeModel{
私有字符串attributeName;
私有列表属性值;
公共产品AttributeModel(字符串attributeName,列表AttributeValue){
this.attributeName=attributeName;
this.attributeValues=attributeValues;
}
公共字符串getAttributeName(){
返回属性名;
}
公共void setAttributeName(字符串attributeName){
this.attributeName=attributeName;
}
公共列表getAttributeValue(){
返回属性值;
}
public void setAttributeValue(列出AttributeValue){
this.attributeValues=attributeValues;
}
@凌驾
公共字符串toString(){
返回“ProductAttributeModel{”+
“attributeName=”+attributeName+“\”+
“,AttributeValue=“+AttributeValue+
'}';
}
}
问题是我在模型中放了一个包含4个模型的列表,而微调器只显示其中的一个。我错过了什么

我试图迭代字符串数组的大小,并将它们添加到每一行项中,但由于某种原因,它似乎覆盖了它的工作,不添加字符串,而是逐个重写

编辑-这是创建适配器时的完整方法-

@覆盖
public void setProductPurchaseAttributes(){
selectedProductAttributesMap=selectedProduct.getAttributesList();
/*起始索引是我们开始添加表示产品属性的动态线性布局的索引。
每当我们对“activity\u product\u page.xml”文件进行任何更改时,这个数字应该增加1,否则动态视图
将在错误的位置创建。
*/
int启动指数=7;
如果(!isProductAvailable)返回;
ArrayList productAttributeModels=新的ArrayList();
对于(Map.Entry:selectedProductAttributesMap.entrySet()){
//每个迭代的键和值
String key=entry.getKey();
列表值=entry.getValue();
//创建线性布局
LinearLayout LinearLayout=新的LinearLayout(本);
linearLayout.setOrientation(linearLayout.HORIZONTAL);
//创建布局参数
LinearLayout.LayoutParams attributeLayoutParams=新的LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_父级,ViewGroup.LayoutParams.WRAP_内容);
LinearLayout.LayoutParams spinnerParams=新的LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_父级,ViewGroup.LayoutParams.WRAP_内容);
LinearLayout.LayoutParams textParams=新的LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容);
//设置边距
/*这些边距值与活动的XML中的值不同,因为这是一个动态创建的vi
ArrayList<ProductAttributeModel> productAttributeModels = new ArrayList<>();

for (Map.Entry<String, List<String>> entry : selectedProductAttributesMap.entrySet()) {
//Key and value for each iteration

  String key = entry.getKey();
  List<String> value = entry.getValue()

  productAttributeModels.add(new ProductAttributeModel(key, value));
   
}
  ColorAttributeArrayAdapter adapter = new ColorAttributeArrayAdapter(this, productAttributeModels);
   spinner.setOnItemSelectedListener(this);
   spinner.setAdapter(adapter);