我有一个类fragmentProducts.java,我在listview中加载我的产品。
进入我的xml布局,我有文本和两个微调器,一个用于大小,一个用于颜色。文本的一切都可以,它们会被显示出来。我对微调器有问题,因为我认为我应该在 GetView 中添加 arrayAdapter 。 我得到致命异常:E / AndroidRuntime(29244):android.content.res.Resources $ NotFoundException:资源ID#0x7f0a005b类型#0x12在android.content.res.loadXMLResourceParser(Resources.java:2407)无效...
使用ViewHelper类的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函数吗?
答案 0 :(得分:0)
资源$ NotFoundException:资源ID#0x7f0a005b类型#0x12
由于ArrayAdapter
采用布局ID 而不是查看ID 作为第二个参数。
var1Adapter = new ArrayAdapter<String>(getActivity(),
<Layout_Id_In_Which_Spinner_Added>,names);
答案 1 :(得分:0)
谢谢你,不幸的是我无法用你的答案工作:
var1Adapter = new ArrayAdapter<String>(getActivity(),R.id.layoutspOptions1,names)
。
// layoutspOptions1是我有微调器的linearLayout id。
虽然通过将arrayAdapter更改为:
来起作用`var1Adapter = new ArrayAdapter(getActivity(),android.R.layout.simple_spinner_item,names);
var1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);`
因此,我们不使用R.id.spinnerId作为ArrayAdapter的第二个参数,而是使用默认布局:android.R.layout.simple_spinner_item