当我尝试下面的代码行
时ItemRow itemdata = data.get(position);
在ItemAdapter类中我收到了错误
不兼容的类型:com.fragment.ItemRow found:java.lang.object
完整的ItemRow.java类如下:
Package com.fragments;
import android.graphics.drawable.Drawable;
public class ItemRow {
String itemName;
Drawable icon;
public ItemRow(String itemName, Drawable icon) {
super();
this.itemName = itemName;
this.icon = icon;
}
public String getItemName() {
return itemName;
}
public void setItemName(String itemName) {
this.itemName = itemName;
}
public Drawable getIcon() {
return icon;
}
public void setIcon(Drawable icon) {
this.icon = icon;
}
}
和完整的Itemadapeter类,当我尝试
时,我得到了不兼容的类型-ItemRow itemdata = data.get(position);在getView中
package com.fragments;
public class ItemAdapter extends ArrayAdapter {
List data;
Context context;
int layoutResID;
public ItemAdapter(Context context, int layoutResourceId,List data) {
super(context, layoutResourceId, data);
this.data=data;
this.context=context;
this.layoutResID=layoutResourceId;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
NewsHolder holder = null;
View row = convertView;
holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResID, parent, false);
holder = new NewsHolder();
holder.itemName = (TextView)row.findViewById(R.id.example_itemname);
holder.icon=(ImageView)row.findViewById(R.id.example_image);
holder.button1=(Button)row.findViewById(R.id.swipe_button1);
holder.button2=(Button)row.findViewById(R.id.swipe_button2);
holder.button3=(Button)row.findViewById(R.id.swipe_button3);
row.setTag(holder);
}
else
{
holder = (NewsHolder)row.getTag();
}
ItemRow itemdata = data.get(position);
holder.itemName.setText(itemdata.getItemName());
holder.icon.setImageDrawable(itemdata.getIcon());
holder.button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "Button 1 Clicked",Toast.LENGTH_SHORT).show();
}
});
holder.button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "Button 2 Clicked",Toast.LENGTH_SHORT).show();
}
});
holder.button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(context, "Button 3 Clicked",Toast.LENGTH_SHORT);
}
});
return row;
}
static class NewsHolder{
TextView itemName;
ImageView icon;
Button button1;
Button button2;
Button button3;
}
}
答案 0 :(得分:1)
您的列表raw type
表示Object
,因此您必须将Object
下载到您的POJO,即ItemRow
ItemRow itemdata = (ItemRow )data.get(position);
或者您应该有List<ItemRow>
类型的列表,因为您不知道要将哪种类型的列表传递给此适配器,因此请确保在此案例中传递与List<ItemRow>
相同的类型以及要遵循最佳做法,请将适配器类型提及为extends ArrayAdapter<ItemRow>
,并在其他位置进行必要的更改。
答案 1 :(得分:1)
请使用List<ItemRow>
代替List
。
答案 2 :(得分:0)
问题是由List data;
ArrayList<ItemRow> data;
相反,试试这个
@Pointcut("execution(*com.shop.controller.OrderController.save(..))")
public void savingOrder() {
log.info("Saving order details");
}
@Before("savingOrder() && args(..,request)")
public void logSavingOrder(JoinPoint joinPoint, HttpServletRequest request){
log.info("Saving");
}