weight_table_menu.xml
<?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="wrap_content"> <TextView android:id="@+id/textViewTableMenuItem" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:text="ویرایش" android:paddingRight="12dp" android:paddingEnd="12dp" android:paddingTop="8dp" android:paddingBottom="10dp" android:textColor="@android:color/black" android:textSize="16sp"/> </RelativeLayout>
WeightTableAdapter.java
String[] menuItems = context.getResources().getStringArray(R.array.table_menu); ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.weight_table_menu, R.id.textViewTableMenuItem, menuItems); final ListPopupWindow listPopupWindow = new ListPopupWindow(context); listPopupWindow.setAdapter(adapter); listPopupWindow.setAnchorView(button); listPopupWindow.setWidth(420); listPopupWindow.setHeight(ListPopupWindow.WRAP_CONTENT); listPopupWindow.setHorizontalOffset(-380); listPopupWindow.setVerticalOffset(-50); //listPopupWindow.setContentWidth(200); listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position==0) { } else if (position==1) { historyList.remove(viewHolder.getAdapterPosition()); notifyItemRemoved(viewHolder.getAdapterPosition()); } listPopupWindow.dismiss(); } }); listPopupWindow.show();
References
https://stackoverflow.com/questions/9906786/display-listpopupwindow-on-most-left-of-the-screen