Stack Exchange
how to add notifyDataSetChanged method in base adapter
how to update GridView in my code  when i used this  code cla.notifyDataSetChanged; is say cannot resolve how to add notifyDataSetChanged method in my adapter class? please help me what do u do? my adapter class not have notifyDataSetChange method
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);

Adapter Class
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;
    }

}


cla.notifyDataSetChanged() is correct. What is your error here?

where i place this line? before this line listview.setAdapter(cla); or after this line??

where i place cla.notifyDataSetChanged()   before gridView.setAdapter(cla); or after gridView.setAdapter(cla);

Place it where do you want to update your UI. Some onclick listeners.

what is ur requirement?..be clear..

my gridview not refresh when getting data fromurl when i go previous activity and againcome on current activity then is show images

what does  gridView.invalidate();
gridView.invalidateViews(); this two commands do??

please tell me the sequence like (1)gridView.setAdapter(cla);below this (2) cla.notifyDataSetChanged() ;  below this (3) gridView.invalidate();

which 1 will come on first and so on

after gidView.setAdapter(cla);
necause before that line your adapter is not set yet..
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..

i just want every time actoivity start my grid refresh so which call first  cla.notifyDataSetChanged() or gidView.setAdapter(cla);

first, you can't call cla.notifyDataSetChanged() before you call gidView.setAdapter(cla); because the adapter does not work until you set it in the ( gidView.setAdapter(cla); ) line.. so you wont have anything to notify changes to.. so you need to put this line gidView.setAdapter(cla); BEFORE this line cla.notifyDataSetChanged(). BUT if you dont make any changes to the gridview (Adding/Deleting.. photos) you DONT NEED to call cla.notifyDataSetChanged() at all.. because this line is meant to be called DURING RUNTIME, you dont need to call it when the app starts..

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

According to your question what I understood is you want the correct place for notifyDataSetChanged() method
Solution is notifyDataSetChanged() is used when the adapter data changes, hence initially when you filled the array it's static and will not get changed so not needed here. so after that according to your logic if
static ArrayList<String> Category_name = new ArrayList<String>();
static ArrayList<String> Category_image = new ArrayList<String>();

Changes after that you have to call 
cla.notifyDataSetChanged() 

which will refresh the listview.

i call cla.notifyDataSetChanged()  before this line or after? gridView.setAdapter(cla);

It's always after setting the adapter so after this line only, and you should call this only when your data for adapter is changed
