Note that there are some explanatory texts on larger screens.

plurals
  1. POCursorAdapter not calling newView or bindView android
    primarykey
    data
    text
    <p>I am trying to display images from a database in a <code>GridView</code> within a <code>Fragment</code>. For some reason, the CursorAdapter's <code>newView()</code> or <code>bindView()</code> method is not getting called. Here is my code:</p> <p>GridImageAdapter.java class:</p> <pre><code>public class GridImageAdapter extends CursorAdapter { private static String TAG = "Image_Debug"; private Context mContext; private int count; private String columnname; public GridImageAdapter(Context context,Cursor cursor,int flag){ super(context,cursor,flag); this.mContext = context; //this.columnname = columnname; Log.d(TAG, "calling grid imageadapter now"); } @Override public int getCount() { return count; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } /*@Override public View getView(int position, View convertView, ViewGroup parent) { ImageView image; ViewHolder holder; if(convertView == null) { LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.media_view, null); holder = new ViewHolder(); holder.image = (ImageView)convertView.findViewById(R.id.media_image_id); convertView.setTag(holder); } else { holder = (ViewHolder)convertView.getTag(); } // holder.image.setImageBitmap((position).getBitmap()); return convertView; }*/ @Override public void bindView(View view, Context context, Cursor cursor) { Log.d(TAG, "calling bind view"); ViewHolder holder = (ViewHolder)view.getTag(); String name = cursor.getString(cursor.getColumnIndexOrThrow(WeatherImageDB.CLOUDY)); Log.d(TAG, "string name in gridimageadapter is" + name); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeFile(name); Bitmap newbitmap = Bitmap.createScaledBitmap(bitmap, 120, 120, false); holder.image.setImageBitmap(newbitmap); } @Override public View newView(Context context, Cursor cursor, ViewGroup container) { Log.d(TAG, "calling new view here"); ViewHolder holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.media_view, container, false); holder.image = (ImageView)view.findViewById(R.id.media_image_id); view.setTag(holder); return view; } } class ViewHolder { ImageView image; TextView item_name; } </code></pre> <p>and from fragment:</p> <pre><code>public class PhotoFragment extends Fragment implements LoaderCallbacks&lt;Cursor&gt; { private static final int FRIENDS_LOADER = 0; private static final int MYLOADER_LOADER = 1; TextView text; GridView grid; GridImageAdapter imageAdapter; PhotoDB dbadapter; public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); dbadapter = new PhotosDB(getActivity().getApplicationContext()); //database class getActivity().getSupportLoaderManager().initLoader(FRIENDS_LOADER, null, this); } @Override public void onActivityCreated(Bundle savedInstanceState){ super.onActivityCreated(savedInstanceState); setRetainInstance(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View view = inflater.inflate(R.layout.my_tags, container, false); text = (TextView)view.findViewById(R.id.my_header_text_id); grid = (GridView)view.findViewById(R.id.my_tag_gridview_id); grid.setClipToPadding(false); imageAdapter = new GridImageAdapter(getActivity().getApplicationContext(), null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); grid.setAdapter(imageAdapter); return view; } @Override public Loader&lt;Cursor&gt; onCreateLoader(int id, Bundle args) { switch(id){ case FRIENDS_LOADER: return new CustomCursorLoader(getActivity().getApplicationContext(), dbadapter,PhotoDB.FRIENDS); case MY_LOADER: return new CustomCursorLoader(getActivity().getApplicationContext(),dbadapter,PhotoDB.MYFOTOS); } return null; } @Override public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor data) { if(loader.getId() == 0){ imageAdapter.swapCursor(data); text.setText("Friend Photos"); } @Override public void onLoaderReset(Loader&lt;Cursor&gt; args) { imageAdapter.swapCursor(null); } public static final class CustomCursorLoader extends SimpleCursorLoader { String columnname; PhotoDB dbadapter; public CustomCursorLoader(Context context, PhotoDB dbadapter, String columnname){ super(context); this.dbadapter = dbadapter; this.columnname = columnname; } public CustomCursorLoader(Context context,String columnname){ super(context); this.columnname = columnname; } @Override public Cursor loadInBackground() { Cursor cursor = null; dbadapter.open(); Log.d(TAG, "retrieving tag from database now"); cursor = dbadapter.retrieveTag(columnname); return cursor; } } } </code></pre> <p>So, my question is, why is the <code>CursorAdapter</code> not calling the <code>newView()</code>/<code>bindView()</code> methods? I can't even get the logcat output on those methods, so I know it's not reaching there. Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload