I am using loaders to load data into a gridview . First let me show you some code:-
The Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle icic){
View v=inflater.inflate(R.layout.thegrid, container, false);
final GridView gv = (GridView)v.findViewById(
R.id.thegridview);
gv.setAdapter(upAd);//upAd is the array adapter initialized in oncreate of the fragment
gv.setOnItemClickListener(this);
Bundle args=new Bundle();
args.putString("page", String.valueOf(page));
getLoaderManager().initLoader(1, args, this);
return v;
}
@Override
public Loader<ArrayList<HashMap<String, String>>> onCreateLoader(int loaderId,Bundle thebundle) {
if(loaderId==1){
String page=thebundle.getString("page");
return new MyLoader(getActivity().getApplicationContext(),page);
}
return null;
}
@Override
public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> theLoader,ArrayList<HashMap<String, String>> data) {
upAd.addAll(data);
}
Now when the fragment is displayed , it shows a grid of 10 elements downloaded.Now when the screen orientation is changed, the loader behaves well and does not download the data again but it adds the same data again to the grid.. so i end up having a grid of 20 elements the same 10 repeated twice. Well i can call :-
upAd.clear()
in onLoadFinished but i want to avoid that.Could someone tell me what would I be doing wrong here.