I want to set touchable for my image view and how i get position for image view of each line in list view ?
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// when the view will be created for first time,
// we need to tell the adapters, how each item will look
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.list_shipments, parent, false);
return retView;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
}
}
The Cursor
is already positioned at the exact row when called newView
or bindView
. All you need is set onClick or OnTouch listener:
@Override
public View newView(Context context, Cursor cursor, ViewGroup viewGroup)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.list_shipments, parent, false);
ViewHolder holder = new ViewHolder(view);
view.setTag(holder);
return view;
}
@Override
public void bindView(View view, final Context context, Cursor cursor)
{
ViewHolder holder = (ViewHolder) view.getTag();
holder.image.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// do something
}
}
Some code for ViewHolder
:
public static class ViewHolder
{
private ImageView image;
public ViewHolder(View view)
{
image = (ImageView) view.findViewById(R.id.image);
}
}