I am trying to recreate the ListView seen in Android 4.0 Music player, which allows you to access by ContextMenuclicking the area to the right of the line:

To do this, I create complex ListFragment strings using RelativeLayout. It was pretty easy to recreate:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/row_select">
<RelativeLayout
android:id="@+id/grabber"
android:layout_width="22dip"
android:layout_height="110dip"
android:layout_alignParentLeft="true"
android:clickable="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/grabber" />
</RelativeLayout>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="end"
android:paddingTop="10dip"
android:layout_marginLeft="5dip"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/grabber"
android:layout_toLeftOf="@+id/playlist_context"
android:textAppearance="@style/Title"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/title"
android:layout_alignRight="@+id/title"
android:layout_below="@+id/title"
android:textAppearance="@style/Subtitle"
android:lines="1"
android:ellipsize="end" />
<TextView
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dip"
android:layout_alignLeft="@+id/title"
android:layout_alignRight="@+id/title"
android:layout_below="@+id/subtitle"
android:textAppearance="@style/body"
android:lines="2"
android:ellipsize="end" />
<RelativeLayout
android:id="@+id/playlist_context"
android:layout_width="26dip"
android:layout_height="110dip"
android:layout_alignParentRight="true"
android:clickable="true"
android:background="@drawable/row_select">
<ImageView
android:id="@+id/playlist_context"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:paddingBottom="15dip"
android:src="@drawable/triangle" />
</RelativeLayout>
<TextView
android:id="@+id/hidden_id"
android:layout_width="0dip"
android:layout_height="0dip"
android:visibility="gone" />
</RelativeLayout>
I also use my own CursorAdapterto populate each line using bindView(View view, Context context, Cursor c).
Now I need to show ContextMenufor the row when I click this row R.id.playlist_context. This area with a click is highlighted in red in the screenshot above. In bindViewI can install onClickListener:
((RelativeLayout)view.findViewById(R.id.playlist_context)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i("PlaylistCursorAdapter", "Clicked something");
}
});
It works by spelling “Click Something” every time I click on RelativeLayout.
ContextMenu, , registerForContextMenu(getListView()); ListFragment. .
, . ✓ ContextMenu ListFragment.
, .. ContextMenu RelativeLayout?
!