I have a Custom List view that works perfectly. Now, I want to have a drop down menu for each item in the list so that when the user taps on any item of the list,the drop down menu shows two options-edit and delete. According to the user's choice the list view item is taken care of.
I want to know the method of adding the drop down menu to each listview item.
xml file for list items-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="120dp"
android:background="#FFFFFF">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:id="@+id/chkitem"
android:layout_alignParentLeft="true"
/>
<TextView android:id="@+id/textTitle"
android:layout_width="200dp"
android:layout_height="60dp"
android:textSize="15dp"
android:textColor="#000000"
android:textStyle="bold"
android:gravity="fill"
android:layout_toRightOf="@+id/chkitem"
/>
<TextView
android:layout_width="200dp"
android:layout_height="60dp"
android:id="@+id/detail"
android:textSize="15dp"
android:textStyle="italic"
android:gravity="fill"
android:layout_toRightOf="@+id/chkitem"
android:layout_below="@+id/textTitle"/>
</RelativeLayout>
adapter class
public class list_addr_adapter extends ArrayAdapter<list_addr> {
Context context;
int layoutResourceId;
public list_addr_adapter(Context context, int layoutResourceId, List<list_addr> items) {
super(context, layoutResourceId, items);
this.layoutResourceId = layoutResourceId;
this.context = context;
// this.listener=callback;
}
/*private view holder class*/
private class ViewHolder {
TextView txtTitle;
TextView txtDetail;
}
ViewHolder holder = null;
public View getView(int position, View convertView, ViewGroup parent) {
final list_addr lists = getItem(position);
final int pos=position;
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.items_sav_addr2, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.textTitle);
holder.txtDetail = (TextView) convertView.findViewById(R.id.detail);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.txtTitle.setText(lists.getTitle());
holder.txtDetail.setText(lists.getDetail());
return convertView;
}
}
I want it to be something like this -
Check This:
Xml:
Adapter Class:
Popup menu.xml
Refer This: Android List view layout Similar to Google play