I've designed a GridView with custom item layout and there is one ImageView on the top-left corner, another ImageView on the top-right corner, a main ImageView and Text in the center.
I need to set the OnClickListener for both two ImageView on the corner and the OnItemClickListener for the adapter.
Everything worked fine but only the first item in the GridView can't trigger the OnClickListener. Can anyone solve this problem?
P.S. I found the first item ImageView's OnClickListener will trigger when I do the next action(e.g. Click other items)
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
TagView tag;
if (convertView == null) {
v = m_LayoutInflater.inflate(R.layout.mydoc_grid_item, null);
tag = new TagView(
(ImageView) v.findViewById(R.id.myDoc_GridItem_IV),
(TextView) v.findViewById(R.id.myDoc_GridItem_TV),
(ImageView) v.findViewById(R.id.iViewAdd2Category),
(ImageView) v.findViewById(R.id.iViewDelete));
v.setTag(tag);
} else {
tag = (TagView) v.getTag();
}
v.setLayoutParams(new GridView.LayoutParams((int) (180 * v
.getResources().getDisplayMetrics().density), (int) (180 * v
.getResources().getDisplayMetrics().density)));
tag.image.setScaleType(ImageView.ScaleType.CENTER_CROP);
tag.image.setImageDrawable(new BitmapDrawable(BitmapFactory.decodeFile(m_DisplayItems.get(position)
.get("image").toString())));
tag.text.setText(m_DisplayItems.get(position).get("text").toString());
tag.iAdd2Category.setVisibility((m_IsEdit) ? View.VISIBLE : View.GONE);
tag.iDelete.setVisibility((m_IsEdit) ? View.VISIBLE : View.GONE);
if (m_IsEdit) {
tag.iAdd2Category.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(LOG_TAG, "Click on image add 2 category");
}
});
tag.iDelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(LOG_TAG, "Click on image delete");
}
});
}
return v;
}
Mixing OnClickListeners and OnItemClickListeners for list's items doesn't work well.
In your case you should probably use multiple OnClickListeners on the different parts of your item and not use OnItemClickListener at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With