Hi,

I want to have gallery widget in preference screen. I have created custom
preference with Gallery.
I am able to display images but there is couple of problem with it.

1. I want to scale the image which is selected in gallery. i used
setOnItemselected listener and it does scale the image but when i selected
other item it doesn't go back to original size.
2. In the preference setUnselectedAlpha is also not working. it works on
initial load but not after that.

Here is the my preference Code.

*I would really appreciate if you can help me. *
Thanks
Yash Patel


*Preference Code*
package com.MarbleBoard;


import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.util.Log;
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.OnItemSelectedListener;

public class marlleGalleryPreference extends Preference {
    public marlleGalleryPreference(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
        Initliazed();
    }

    public marlleGalleryPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        Initliazed();
    }

    public marlleGalleryPreference(Context context) {
        super(context);

        Initliazed();
    }
     private void Initliazed() {
            setPersistent(true);
            //setDialogLayoutResource(R.layout.pref_marble_list);
            setLayoutResource(R.layout.marble_gallery);
            //setDialogTitle("Dialog Title Marble Select");
            //setDialogMessage("Thanks for choosing my custom dialog
preference");
              setEnabled(true);
              setSelectable(true);

        }
    @Override
    protected void onBindView(View view) {
        // TODO Auto-generated method stub
        super.onBindView(view);
         Gallery g = (Gallery) view.findViewById(R.id.gallery);
         g.setFocusable(true);
         g.setFocusableInTouchMode(true);
         g.setUnselectedAlpha(0.5f);
         g.setAdapter(new ImageAdapter(getContext()));
         g.setSpacing(2);
    }

    // *Image Adapter code*
     private class ImageAdapter extends BaseAdapter {
            int mGalleryItemBackground;

            public ImageAdapter(Context c) {
                mContext = c;
            }

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

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

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

            public View getView(int position, View convertView, ViewGroup
parent) {
                ImageView i = new ImageView(mContext);

                i.setImageResource(mImageIds[position]);
                i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                i.setLayoutParams(new Gallery.LayoutParams(80, 60));

               //i.setFocusableInTouchMode(true);
                // The preferred Gallery item background
                //i.setBackgroundResource(mGalleryItemBackground);

                return i;
            }


            private Context mContext;

            private Integer[] mImageIds = {
                    R.drawable.marble_blue,
                    R.drawable.marble_green,
                    R.drawable.marble_lgreen,
                    R.drawable.marble_purple,
                    R.drawable.marble_red
            };
        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to