In einer Anwendung verwende ich ein Galerie-Widget mit einem ImageView und eine Schaltfläche. Ich bin in der Lage, die Imageview auf gallery.setOnItemClickListener Ereignis zu klicken, aber ich bekomme nicht einen Button klicken. Wie kann ich den Button klicken? Bitte hilf mir.Galerie nicht klicken klicken
Bitte schauen Sie in 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 Eltern 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 Kind 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>
Ich mag aslo die Position des ausgewählten Galerie Bildes erhalten .Wie bekomme ich das? – Arun
können wir diese Position des Artikels von gallery.setOnItemClickListener() erhalten, überprüfen Sie meine Antwort jetzt –
Vielen Dank für die Lösung. Dieser Code hat mir sehr geholfen. – Arun