I am creating a CMS application and I want to delete an item, for that I need the ID that I have hidden in the listview item. When I hold a listview item it pops up with a delete button which I click, that brings me to this piece of code:
@Overridepublic boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); switch(item.getItemId()) { case R.id.delete: new HttpDelete("http://test.soundwave.drieo.nl/api/content/"+ text + apikey); return true; default: return super.onContextItemSelected(item); }}
Custom listview:
When hold clicking on an item this appears which calls the code. (Verwijderen == delete)
Custom Row XML for custom adapter:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="?android:attr/listPreferredItemHeight"android:padding="6dip"><ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignParentBottom="true" android:layout_alignParentTop="true" android:layout_marginEnd="6dip" android:contentDescription="@string/TODO"/><TextView android:id="@+id/secondLine" android:layout_width="fill_parent" android:layout_height="26dip" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:layout_toEndOf="@id/icon" android:ellipsize="marquee" android:singleLine="true" android:text="@string/description" android:textSize="12sp" android:visibility="visible"/><TextView android:id="@+id/firstLine" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="@id/secondLine" android:layout_alignParentEnd="true" android:layout_alignParentTop="true" android:layout_alignWithParentIfMissing="true" android:layout_toEndOf="@id/icon" android:gravity="center_vertical" android:text="@string/Example" android:textSize="16sp" /><TextView android:id="@+id/tbid" android:layout_width="fill_parent" android:layout_height="26dip" android:ellipsize="marquee" android:singleLine="true" android:text="@string/ID" android:textSize="12sp" android:layout_alignTop="@+id/secondLine" android:layout_toEndOf="@+id/icon" android:layout_marginStart="68dp" android:visibility="invisible"/></RelativeLayout>