我想创建类似以下的布局微调器 -
我目前拥有的——
我的代码 -
private MiniProductModel selectedProduct;
private Map<String, List<String>> selectedProductAttributesMap;
.
.
.
.
@Override
public void setProductPurchaseAttributes() {
selectedProductAttributesMap = selectedProduct.getAttributesList();
int startingIndex = 6;
if (!isProductAvailable) return;
for (Map.Entry<String, List<String>> entry : selectedProductAttributesMap.entrySet()) {
//creating the linear layout
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
//creating the layout params
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(25,30,25,0);
linearLayout.setLayoutParams(params);
//creating the text view
TextView textView = new TextView(this);
textView.setText(entry.getKey().concat(":"));
textView.setLayoutParams(params);
//creating the spinner
Spinner spinner = new Spinner(this);
spinner.setLayoutParams(params);
ArrayAdapter<String> adapter = new ArrayAdapter<>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, entry.getValue());
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
//adding to the linear layout
linearLayout.addView(textView);
linearLayout.addView(spinner);
//adding linear layout to root view
productDetailsViewGroup.addView(linearLayout, startingIndex);
startingIndex++;
}
}
我正在使用默认数组适配器,它为我提供了仅包含 TextView 的 ViewHolders 列表。
我希望能够根据需要编辑每个持有人,这样我就可以在 eBay 中显示像图片一样的图像。
给定我的代码,我该怎么做?