I have grid view with custom adapter implementation. On touching the grid view item, the entire item is selected. I want to perform different action on selecting different sub item in grid view.
In the below example, I have two images and one textview in the item. I want to perform different action on touching textview, image view.
Is this possible to do that in android ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listrow"
android:layout_width="fill_parent"
android:layout_height="66dp"
android:background="@drawable/grid_color_selector"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="fill_horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="horizontal" >
<ImageView
android:id="@+id/thumbimage"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="4dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:scaleType="fitXY"
android:src="@drawable/icon" />
<TextView
android:id="@+id/txttitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:layout_weight="44"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="English Channels"
android:textColor="@color/Black"
android:textSize="16sp" />
<ImageView
android:id="@+id/share"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="4dp"
android:layout_weight="1"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:scaleType="fitXY"
android:src="@drawable/share" />
</LinearLayout>
The custom gridview implementation is
public class GridViewAdapterImpl extends ArrayAdapter < String > {
private final Activity context;
private final String[] data;
private int resource;
public GridViewAdapterImpl(Activity context, int resource, String[] fileNames) {
super(context, resource, fileNames);
this.resource = resource;
this.context = context;
this.data = fileNames;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(resource, parent, false);
holder = new ViewHolder();
holder.imageTitle = (TextView) row.findViewById(R.id.txttitle);
row.setTag(holder);
} else {
holder = (ViewHolder) row.getTag();
}
holder.imageTitle.setText(data[position]);
return row;
}
static class ViewHolder {
TextView imageTitle;
}
The Gridview call is
GridView gridView = (GridView) findViewById(R.id.gridView);
GridViewAdapterImpl customGridAdapter = new GridViewAdapterImpl(this, R.layout.row_list_videos, this.getVideoFiles()); gridView.setAdapter(customGridAdapter);
gridView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { < Perform action > } });