This should work
//Activity windows height int totalHeight = getWindowManager().getDefaultDisplay().getHeight(); int[] location = new int[2]; v.getLocationOnScreen(location);
The location array must have the x and y values ββof the view. 'v' is the view object passed to onItemClickListener.
I add some parts that I used for my project. This may be helpful. I had an action bar at the top of the list, and this code worked fine.
The requirement was to bring a small menu either above or below the list item. Therefore, when an item is selected, I check if the selected list item is in the upper half of the screen, if so, the menu below the list item otherwise places it on top of the list item. Here is the code
ClickItem Click Code
listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position , long id) { showQuickActionMenu(position,view); } }); private void showQuickActionMenu(int pos, View v){ LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
In this class PopupHelper I use
public class PopupHelper { public static final int UPPER_HALF = 0; public static final int LOWER_HALF = 1; public static PopupWindow newBasicPopupWindow(Context context) { final PopupWindow window = new PopupWindow(context);
source share