我有一個類fragmentProducts.java,我加載我的產品在一個列表視圖。動態加載微調到getview
進入我的xml佈局,我有文本和兩個spinners,一個用於大小和一個用於顏色。一切都是好的文本,他們顯示。我對spinners有個問題,因爲我認爲我應該添加一個arrayAdapter到GetView。 我得到致命的異常:E/AndroidRuntime(29244):android.content.res.Resources $ NotFoundException:資源ID#0x7f0a005b類型#0x12在android.content.res.loadXMLResourceParser(Resources.java:2407)無效。 ..
我與視圖助手類GetView代碼,是這樣的:
`private class ViewHolder {
TextView prName;
TextView prDescription;
TextView prfprice;
ImageView prImage;
//spinners
Spinner PrVariants;
Spinner PrOptions;
int ProdPosition;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
View view = convertView;
final ProductsData info = getItem(position);
if (view == null) {
// Product row
view = mInflater.inflate(R.layout.productslistitem_layout, null);
viewHolder = new ViewHolder();
assert view != null;
viewHolder.prName = (TextView) view.findViewById(R.id.product_name);
viewHolder.prDescription = (TextView) view.findViewById(R.id.product_description);
viewHolder.prfprice = (TextView) view.findViewById(R.id.product_fprice);
viewHolder.prImage = (ImageView) view.findViewById(R.id.product_image);
**//here i try to put test values on the spinner//**
viewHolder.PrVariants = (Spinner) view.findViewById(R.id.spOptions1);
String[] names = {"test1","test2","test3"};
var1Adapter = new ArrayAdapter<String>(getActivity(),R.id.spOptions1,names);
var1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
viewHolder.PrVariants.setAdapter(var1Adapter);
viewHolder.prfprice.setText("120.00" + "€");
viewHolder.prName.setText(info.getPrName());
viewHolder.prDescription.setText(info.getPrComments());
view.setTag(viewHolder);
} else
viewHolder = (ViewHolder) view.getTag();
return view;
}`
有誰理解的錯誤消息?我應該不使用arrayadapter進入GetView函數嗎?
我將微調器和其他所有組件一起放入了productslistitem_layout.xml文件中。 – user3520356 2014-09-21 12:05:13
@ user3520356:然後在ArrayAdapter中傳遞'R.layout.productslistitem_layout'作爲第二個參數 – 2014-09-21 12:07:03