In ma application I am using a gallery widget having an ImageView and a button. I am able to get the Imageview click on gallery.setOnItemClickListener event, but I am not getting ma button click . how can I get the button click. Please help me.
Please look into ma code:
public ImageAdapter(Activity c,Integer[] images) {
this.mContext = c;
this.Images=images;
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGal999lery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGal999lery_android_galleryItemBackground, 0);
attr.recycle();
}
public int getCount() {
return Images.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return 1;
}
public boolean onInterceptTouchEvent(MotionEvent __e) {
return false;
}
static class ViewHolder{
public ImageView imageView1;
public ImageButton btn1;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View rowView = convertView;
if(rowView==null)
{
LayoutInflater inflater = mContext.getLayoutInflater();
rowView = inflater.inflate(R.layout.test, null, true);
holder=new ViewHolder();
holder.imageView1=(ImageView) rowView.findViewById(R.id.ImageViewuser);
holder.btn1=(ImageButton)rowView.findViewById(R.id.Download);
holder.imageView1.setImageResource(Images[position]);
holder.imageView1.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
holder.imageView1.setBackgroundResource(mGalleryItemBackground);
}
// rowView.setMinimumHeight(100);
return rowView;
}
Ma parent layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:spacing="10dp"
android:layout_height="fill_parent" />
</RelativeLayout>
Ma child layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical" >
<ImageView
android:id="@+id/ImageViewuser"
android:layout_width="150dip"
android:layout_height="150dip"
/>
<ImageButton
android:id="@+id/Download"
android:layout_below="@+id/ImageViewuser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="50dp"
android:background="@drawable/clearall1"
/>
</RelativeLayout>
you did’t wrote code for click events, add onClick() function for button in the
getView()methodyou can get position here
and also
you can get position like this
position of the item in gallery