0

我使用以下代码来更新实体:

    public int SaveCategory(Category category)
    {
        using (MyModel am = this.conn.GetContext())
        {
            if (category.CategoryId > 0)
            {
                am.Category.Attach(category);
                am.Category.ApplyCurrentValues(category);
            }
            else
            {
                am.Category.AddObject(category);
            }
            am.SaveChanges();
        }
        return category.CategoryId;
    }

此方法添加了现有实体的副本,我更改了它的一些值,但我想更新现有实体。
我的错和/或我错过了什么?
感谢您的关注


public class ViewPagerAdapter2 extends PagerAdapter {

Context context;
String[] image1;
String[] description;


LayoutInflater inflater;

public ViewPagerAdapter2(Context context, String[] image1,String[] description) {
    this.context = context;
    this.image1 = image1;
    this.description=description;


}

@Override
public boolean isViewFromObject(View view, Object object) {
    return view == ((LinearLayout) object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {


    TextView des;

    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.slider, container,
            false);
    des = (TextView) itemView.findViewById(R.id.slider_des);
    des.setText(description[position]);

     AQuery aq = new AQuery(itemView);
     aq.id(R.id.imageView1).image(image1[position], true, true, 0, 0, null, AQuery.FADE_IN, AQuery.RATIO_PRESERVE);

     ((ViewPager) container).removeView(itemView);



    ((ViewPager) container).addView(itemView);

    return itemView;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    ((ViewPager) container).removeView((LinearLayout) object);

}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return description.length;

}

}

这正是您想要的实现...现在声明文本视图内容的变量,声明图像视图,将它们绑定在一起...这应该可以工作...在您的活动中,按照声明的顺序将变量传递给适配器. 该解决方案将完美无缺。我使用查询从 url 获取图像。您可以简单地传递图像资源并通过imageview.setImageResource();方法绑定它

4

0 回答 0