In order to handle different view clicking, I set listeners for views in getView(). If a lot of items added, it will be a little slow.
public View getView(int position, View convertView, ViewGroup parent) {
holder.icon_iv = (ImageView) convertView.findViewById(R.id.app_icon_iv);
holder.icon_iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
...
}
});
holder.checkbox_iv = (CheckBox) convertView.findViewById(R.id.history_checkbox_iv);
holder.checkbox_iv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
...
}
});
}
So I wanna do it in onItemClick(), but View arg1 can't tell the difference on views clicking. Can anyone tell me what to do with it?
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
EDIT: Thank you, I decide do like this and it works perfectly:
holder.item_ll.setTag(position);
holder.item_ll.setOnClickListener(mItemClickListener);
holder.checkbox_iv.setTag(position);
holder.checkbox_iv.setOnClickListener(mItemClickListener);
public View.OnClickListener mItemClickListener = new View.OnClickListener() {
public void onClick(View view) {
if (view.getTag() instanceof Integer) {
int position = (Integer) view.getTag();
HistoryItem item = adapter.get(position);
if (view.getId() == R.id.checkbox_iv) {
...
} else if (view.getId() == R.id.item_ll) {
...
}
}
}
};