I have an app which displays data in a fragment(uses webservice). After login, fragment fetches data from json and add to database, after that I want to populate it in my fragment. My fragment shows nothing after adding database.
public class GridFragment extends Fragment {
Context mContext;
GridView gridd;
GridAdapter adapter;
MagazineGetIssues mgi;
ArrayList<DataVal> Issues = new ArrayList<>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
mgi = new MagazineGetIssues();
DBOperation db = new DBOperation(getActivity());
Issues = db.getIssues();
adapter = new GridAdapter(getActivity(), Issues);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_grid, container, false);
gridd = (GridView) rootView.findViewById(R.id.gridViewAA);
gridd.setAdapter(adapter);
//getting Issues
mgi.getIssues(mContext);
adapter.addList(Issues);
return rootView;
}
}
GridAdapter class
public class GridAdapter extends BaseAdapter {
private final FragmentActivity activity;
ImageLoaderConfiguration imageLoaderConfiguration;
DisplayImageOptions displayImageOptions;
String url = "";
DisplayImageOptions imageOptions;
ImageLoader imLoad;
ArrayList<DataVal> issueList = null;
public GridAdapter(FragmentActivity activity, ArrayList<DataVal> cdate) {
this.activity = activity;
this.issueList = cdate;
displayImageOptions = new DisplayImageOptions.
Builder().cacheOnDisk(true).cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.displayer(new FadeInBitmapDisplayer(300))
.build();
imageLoaderConfiguration = new ImageLoaderConfiguration.Builder(activity)
.defaultDisplayImageOptions(displayImageOptions).memoryCache(new WeakMemoryCache())
.discCacheSize(100 * 1024 * 1024).build();
ImageLoader.getInstance().init(imageLoaderConfiguration);
imLoad = ImageLoader.getInstance();
imageOptions = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).resetViewBeforeLoading(true).build();
}
@Override
public int getCount() {
return issueList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
LayoutInflater inflator = activity.getLayoutInflater();
convertView = inflator.inflate(R.layout.grid_single, null);
viewHolder = new ViewHolder();
viewHolder.imView = (ImageView) convertView.findViewById(R.id.CoverPic);
viewHolder.iss_date = (TextView) convertView.findViewById(R.id.issuedate);
viewHolder.iss_price = (TextView) convertView.findViewById(R.id.price);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.iss_date.setText(issueList.get(position).getISSUE_DATE());
viewHolder.iss_price.setText(issueList.get(position).getPRICE());
imLoad.displayImage(url + issueList.get(position).getCOVER_PAGE_THUMB(), viewHolder.imView, imageOptions);
return convertView;
}
public void addList(ArrayList<DataVal> val) {
this.issueList = val;
this.notifyDataSetChanged();
}
static class ViewHolder {
protected TextView iss_date;
protected TextView iss_price;
protected ImageView imView;
}
}
try to replace this line
with
in your
BaseAdapter