I have a listview which has an image.I want to make an action when the image is clicked. Doing that from my adapter , works ,but I want to do it from my mainactivity where the listview lies.
I have my custom adapter:
ImageView myImage=(ImageView) convertView.findViewById(R.id.myimage);
byte []temp = theItems.getImagemyItems();
Bitmap image = BitmapFactory.decodeByteArray(temp, 0, temp.length);
myImage.setImageBitmap(image);
myImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "CLICKED!", Toast.LENGTH_SHORT).show();
}
});
The above works fine. If I try from mainactivity:
View inflatedView = getLayoutInflater().inflate(R.layout.showadapterlist, null);
this.imageView = (ImageView) inflatedView.findViewById(R.id.myimage);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "CLICKED!", Toast.LENGTH_SHORT).show();
}
});
It doesn't work.Nothing happens.