0

When I add a button in the below xml , the setOnItemClickListener doesnt work , when i remove the button i can click on the image and go to another acrivity .. where is the problem ?

I have this xml

<?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"
android:orientation="vertical"
android:background="#cccccc"
android:padding="10dp" >
<ImageView
android:id="@+id/imgIcon"
android:layout_width="200dp"
android:layout_height="200dp"
  />

<TextView
android:id="@+id/txtTitle"
android:layout_width="30dp"
android:layout_height="30dp"
android:paddingLeft="20dp"
android:textSize="16dp"
android:color="#e43eee" />


<Button
android:id="@+id/btnsmile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imgIcon"
android:paddingLeft="30dp"
android:layout_alignParentLeft="true" />
</RelativeLayout>

and this is my adapter

package com.example.sqlfirst;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ContactImageAdapter1 extends ArrayAdapter<Contact>{
Context context;
int layoutResourceId;
ArrayList<Contact> data=new ArrayList<Contact>();
public ContactImageAdapter1(Context context, int layoutResourceId, ArrayList<Contact> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ImageHolder();
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
row.setTag(holder);
}
else
{
holder = (ImageHolder)row.getTag();
}
Contact picture = data.get(position);
holder.txtTitle.setText(picture ._name);
//convert byte to bitmap take from contact class
byte[] outImage=picture._image;
ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
holder.imgIcon.setImageBitmap(theImage);
return row;
}
static class ImageHolder
{
ImageView imgIcon;
TextView txtTitle;
}
}
Moudiz
  • 7,211
  • 22
  • 78
  • 156

0 Answers0