0

GridView当我使用此代码时如何更新我的代码cla.notifyDataSetChanged;说无法解决如何notifyDataSetChanged在我的适配器类中添加方法?请帮帮我你怎么办?我的适配器类没有notifyDataSetChange方法

public class fifthscreen extends Activity {
    private AQuery androidAQuery;
    CategoryListAdapter3 cla;
    androidAQuery = new AQuery(this);
    static ArrayList<String> Category_name = new ArrayList<String>();
    static ArrayList<String> Category_image = new ArrayList<String>();

    cla = new CategoryListAdapter3(fifthscreen.this);
    gidView.setAdapter(cla);

适配器类

public class CategoryListAdapter3 extends BaseAdapter {

    private Activity activity;


    private AQuery androidAQuery;


    public CategoryListAdapter3(Activity act) {
        this.activity = act;
    //  imageLoader = new ImageLoader(act);
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return fifthscreen.Category_ID.size();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder;
        androidAQuery = new AQuery(getcontext());
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.viewitem2, null);
            holder = new ViewHolder();

            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }


        holder.txtText = (TextView) convertView.findViewById(R.id.title2);
        holder.imgThumb = (ImageView) convertView.findViewById(R.id.image2);

        holder.txtText.setText(fifthscreen.Category_name.get(position));


       androidAQuery.id(holder.imgThumb).image(fifthscreen.Category_image.get(position), true,true);

        return convertView;
    }
    private Activity getcontext() {
        // TODO Auto-generated method stub
        return null;
    }
    static class ViewHolder {
        TextView txtText;
        ImageView imgThumb;
    }

}
4

3 回答 3

0

根据您的问题,我的理解是您想要正确的notifyDataSetChanged()方法位置

当适配器数据更改时使用解决方案notifyDataSetChanged(),因此最初当您填充数组时,它是静态的并且不会被更改,因此这里不需要。所以之后根据你的逻辑如果

static ArrayList<String> Category_name = new ArrayList<String>();
static ArrayList<String> Category_image = new ArrayList<String>();

之后的变化你必须打电话

cla.notifyDataSetChanged() 

这将刷新列表视图。

于 2013-10-24T06:44:35.517 回答
0

在 gidView.setAdapter(cla) 之后;necause 在该行之前您的适配器尚未设置..

but you need to decide when to call it, means you call this line ( cla.notifyDataSetChanged() ) after you make a change to one of the adpater's components and you want it to be shown immediately..

于 2013-10-24T06:47:48.757 回答
0

You can refresh that activity itself by using intent but its not a good way!!

于 2013-10-24T07:55:29.993 回答