I would like to implement in my listview the longclick, up there I succeeded perfectly :) Now I would like to create a sort of pop-up with more possibilities, for example, paste, delete, remove, etc ... To make you understand I found a picture on the internet :) Ve mail below. Thank you in advance
OnLong Click ListView Pop-UP
1.2k Views Asked by lillogoal At
3
There are 3 best solutions below
0

I think the preferred way is to use action mode for these types of menus. Take a look at this I think this will have all the info you need. It seems a bit overwhelming, but it's not that bad to implement. http://developer.android.com/guide/topics/ui/menus.html
0

Try this below code..
in java
listView.setOnItemLongClickListener(new OnItemLongClickListener()
{
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View v,
int position, long id) {
// TODO Auto-generated method stub
LayoutInflater layoutInflater= (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.list_popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,155,LayoutParams.WRAP_CONTENT);
ListView listView = (ListView) popupView.findViewById(R.id.list_view);
listView.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1,menu));
popupWindow.showAsDropDown(listView, 50, 0);
return false;
}
});
list_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#44444d"
>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#5c7089"
android:dividerHeight="2dp"
android:layout_marginTop="3dp"/>
</LinearLayout>
Try to use pop menu like this..
}
And xml like this..