• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Gallery and Image View Issues

aallen172

Lurker
I have created an application with multiple buttons and layouts and on each layout I want to show a GalleryView coupled with an ImageView.

I've been able to get everything else to work in my application except for the Gallery and Image Views. I receive no errors in my coding and the layouts associated with the Gallery and Image View only show a blank page after being compiled into my Android Virtual Device.

The application is setup to first show the splash screen and then it is sent to a triple tabbed layout. On each of the tabbed layouts i have multiple buttons that go to their own layouts (without tabs).

The pictures I want displayed are in the Drawable folder as well (in case someone was going to ask).
Please excuse my excessive use of acronyms. The following is Ehm1GalleryActivity.java which is my combined Gallery and Image java file:

Code:
package com.example.ehabmtesting;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Ehm1GalleryActivity extends Activity {
    Integer[] pics = {
            R.drawable.ehm1face,
            R.drawable.ehm1back,
            
    };
    ImageView imageView;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ehm1);
        
        Gallery ga = (Gallery)findViewById(R.id.Gallery01);
        ga.setAdapter(new ImageAdapter(this));
        
        imageView = (ImageView)findViewById(R.id.ImageView01);
        ga.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                Toast.makeText(getBaseContext(), 
                        "You have selected picture " + (arg2+1) + " of Ehm1", 
                        Toast.LENGTH_SHORT).show();
                imageView.setImageResource(pics[arg2]);
                
            }
            
        });
        
    }
    
    
    public class ImageAdapter extends BaseAdapter {

        private Context ctx;
        int imageBackground;
        
        public ImageAdapter(Context c) {
            ctx = c;
            TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
            imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
            ta.recycle();
        }

        public int getCount() {
            
            return pics.length;
        }

        public Object getItem(int arg0) {
            
            return arg0;
        }

        public long getItemId(int arg0) {
            
            return arg0;
        }

        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setImageResource(pics[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(150,120));
            iv.setBackgroundResource(imageBackground);
            return iv;
        }

    }
}
The following, ehm1.xml, is the layout i'm trying to use the Gallery and Image View on:

Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<Gallery 
    android:id="@+id/Gallery01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"></Gallery>
<ImageView 
    android:id="@+id/ImageView01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"></ImageView>
</LinearLayout>
My AndroidManifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.ehabmtesting"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
    

    <application 
        android:icon="@drawable/icon"         
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar">
        
        
        <activity android:name=".SplashActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity android:name=".AndroidTabLayoutActivity" />
              
        <activity android:name=".Level1Activity" />
        
        <activity android:name=".Level2Activity" />
        
        <activity android:name=".Level3Activity" />
        
        <activity android:name=".Ehm1GalleryActivity"/>
            
        <activity android:name=".Ehm1Activity" />
        
        <activity android:name=".Ehm1pActivity" />
                
        <activity android:name=".Ehm2Activity" />
        
        <activity android:name=".Ehm2pActivity" />
        
        <activity android:name=".Ehm3pActivity" />
        
        <activity android:name=".Ehm3Activity" />
        
        <activity android:name=".Ehm4Activity" />
                
        <activity android:name=".Ehm4pActivity" />
        
        <activity android:name=".Ehm5Activity" />
        
        <activity android:name=".Ehm5pActivity" />
        
        <activity android:name=".EhmMixActivity" />
        
        <activity android:name=".EhmMixpActivity" />
        
        <activity android:name=".Bm1Activity" />
        
        <activity android:name=".Bm1pActivity" />
        
        <activity android:name=".Bm2Activity" />
        
        <activity android:name=".Bm2pActivity" />
        
        <activity android:name=".Bm3Activity" />
        
        <activity android:name=".Bm3pActivity" />
        
        <activity android:name=".Bm4Activity" />
        
        <activity android:name=".Bm4pActivity" />
        
        <activity android:name=".Bm5Activity" />
        
        <activity android:name=".Bm5pActivity" />
        
        <activity android:name=".BmixActivity" />
        
        <activity android:name=".BmixpActivity" />
        
        <activity android:name=".L2mixActivity" />
        
        <activity android:name=".L2mixpActivity" />
        
        <activity android:name=".L2mpdActivity" />
        
        <activity android:name=".L2mpdpActivity" />
        
        <activity android:name=".L2wwdActivity" />
        
        <activity android:name=".L2wwdpActivity" />
        
        <activity android:name=".L3bm1Activity" />
        
        <activity android:name=".L3bm1pActivity" />
        
        <activity android:name=".L3bm2Activity" />
        
        <activity android:name=".L3bm2pActivity" />
        
        <activity android:name=".L3bm3Activity" />
        
        <activity android:name=".L3bm3pActivity" />
                
        <activity android:name=".L3bm4Activity" />
        
        <activity android:name=".L3bm4pActivity" />
        
        <activity android:name=".L3bm5Activity" />
        
        <activity android:name=".L3Bm5pActivity" />
        
        <activity android:name=".L3bmixActivity" />
        
        <activity android:name=".L3bmixpActivity" />
        
        <activity android:name=".L3ehm1Activity" />
        
        <activity android:name=".L3ehm1pActivity" />
        
        <activity android:name=".L3ehm2Activity" />
        
        <activity android:name=".L3ehm2pActivity" />
        
        <activity android:name=".L3ehm3Activity" />
        
        <activity android:name=".L3ehm3pActivity" />
        
        <activity android:name=".L3ehm4Activity" />
        
        <activity android:name=".L3ehm4pActivity" />
        
        <activity android:name=".L3ehm5Activity" />
        
        <activity android:name=".L3ehm5pActivity" />
        
        <activity android:name=".L3ehmixActivity" />
        
        <activity android:name=".L3ehmixpActivity" />
        
      </application>
</manifest>
And finally my attributes.xml file:
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Gallery1">
        <attr name="android:galleryItemBackground"/>
    </declare-styleable>
</resources>

Any help would be appreciated.
 
Back
Top Bottom