-2

Possible Duplicate:
How can I dynamically add images to a GridView?

In my application, it allows users to download images from the server and store it into the internal storage. Right after the download completed, the gridview did not update and display the images that downloaded from the server. Unless I restart the application or the activity go through onCreate(). Is there anyway that I can update the gridview dynamically right after the application completed the download process? I tried to refresh the view with invalidateView(); also it's not working. Any comments will be appreciated.

OnCreate()

    final GridView imagegrid = (GridView) findViewById(R.id.WebImageGrid);
    imageAdapter = new ImageAdapter();
    imagegrid.setAdapter(imageAdapter);



    Button loadContent = (Button) findViewById(R.id.load_btn);
    loadContent.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
            if(load_images<count){
                load_images++;
                imageAdapter.LoadImage();
                imagegrid.invalidateViews();
                imagegrid.setAdapter(imageAdapter);
            }
            else{
                Toast.makeText(getApplicationContext(), "Successfully load all the content. Subscribe to get more content.", Toast.LENGTH_SHORT).show();
            }
        }
    });
Community
  • 1
  • 1
IssacZH.
  • 1,457
  • 3
  • 24
  • 54

2 Answers2

2

Grid View Has a function invalidateViews() try using that. it is used to invalidate or re draw all the view again. Put this line after your downloading is complete it will redraw the grid view again. syntax: yourGridView.invalidateViews();

Ravinder
  • 143
  • 1
  • 9
0

Better you use Lazy Loading of Images Concept to achieve your requirement. As you are saying that you are downloading images from web, it is better to user Lazy Loading concept which gives you better performance too. You can have a reference at this link. Here in this link it was shown to load images in listview and your requirement is gridview. Use the same adapter and everything will be working.

TNR
  • 5,839
  • 3
  • 33
  • 62