In the log, when the Activity loads, I can see the Gallery being inflated, the ImageAdapter being set and constructed, but it never calls the getView method of the ImageAdapter. I do see it calling the getCount method twice, but it never tries to load the images. I can verify this both on the Android side (logging statements in the image loading code are never logged) and on the PHP side (the server never gets requests for the images).
The code is based on http://www.androidsnippets.org/snippets/25/
Here's the XML in the layout file to define the gallery:
Using xml Syntax Highlighting
- <Gallery android:id="@+id/gallery"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:gravity="bottom"
- />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4
Here is the code for my Activity's onCreate() method:
Using java Syntax Highlighting
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.gallery_view);
- Gallery gallery = ((Gallery) findViewById(R.id.gallery));
- Log.e("GAL", "found gallery");
- ImageAdapter theAdapter = new ImageAdapter(this);
- gallery.setAdapter(theAdapter);
- Log.e("GAL", "set gallery adapter");
- Button searchButton = (Button)findViewById(R.id.search_button);
- searchButton.setOnClickListener(mSearchClickedHandler);
- Log.e("GALLERY", "in onCreate()");
- ImageView title_bar = (ImageView)findViewById(R.id.banner_image);
- title_bar.setOnClickListener(mTitleBarClickedHandler);
- Bundle extras = getIntent().getExtras();
- String title = (String)extras.getString("title");
- gallery_id = (String)extras.getString("id");
- TextView title_text = (TextView)findViewById(R.id.title_text);
- title_text.setText(title);
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
And here's the inner class ImageAdapter:
Using java Syntax Highlighting
- public class ImageAdapter extends BaseAdapter {
- /** The parent context */
- private Context myContext;
- private int count;
- /** Simple Constructor saving the 'parent' context. */
- public ImageAdapter(Context c) { this.myContext = c;
- Log.e("GAL", "constructed");
- }
- /* Use the array-Positions as unique IDs */
- public Object getItem(int position) { Log.e("GAL", "in getItem returning Object at position " + position);return position; }
- public long getItemId(int position) { Log.e("GAL", "in getItem returning long at position " + position);return position; }
- public View getView(int position, View convertView) {
- ImageView i = new ImageView(this.myContext);
- Log.e("GAL", "in getView with 2 args");
- try {
- String jsonUrl = getString(R.string.api_url) + "?action=galleryimages&id=" + GalleryView.this.gallery_id;
- JSONHandler jsonHandler = new JSONHandler(jsonUrl);
- JSONArray joe = new JSONArray(jsonHandler.getJson());
- count = joe.length();
- JSONObject gallery_entry = joe.getJSONObject(position);
- String img_content_id = gallery_entry.getString("img_content_id");
- String dam_url = getResources().getString(R.string.dam_url) + "/access/show/id/" + img_content_id + "/ds/master/width/120";
- Log.e("DAM", dam_url);
- ImageHandler im = new ImageHandler();
- i.setImageBitmap(im.getBitmap(dam_url));
- i.setScaleType(ImageView.ScaleType.FIT_XY);
- }
- catch (Exception e) {
- Log.e("GAL", "Remote Image Exception", e);
- }
- /* Image should be scaled as width/height are set. */
- i.setScaleType(ImageView.ScaleType.FIT_CENTER);
- /* Set the Width/Height of the ImageView. */
- i.setLayoutParams(new Gallery.LayoutParams(150, 150));
- return i;
- }
- /** Returns the size (0.0f to 1.0f) of the views
- * depending on the 'offset' to the center. */
- public float getScale(boolean focused, int offset) {
- /* Formula: 1 / (2 ^ offset) */
- Log.e("GAL", "in getScale");
- return Math.max(0, 1.0f / (float)Math.pow(2, Math.abs(offset)));
- }
- public int getCount() {
- // TODO Auto-generated method stub
- Log.e("GAL", "in getCount returning int");
- return count;
- }
- public View getView(int arg0, View arg1, ViewGroup arg2) {
- // TODO Auto-generated method stub
- Log.e("GAL", "in getView with 3 args");
- return getView(arg0, arg1);
- }
- }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4
I'd really be thankful for any help anyone can give me with this.
thanks,
Tom


