I would like to have pop up menu, when I click on the 3 dots area in a ListView
row.
Or you can show a dialog, when 3 dots clicked. PopupWindow need to locate where to show on the screen. Show a dialog can indentify witch cloumn you selected.
I know its a bit late and you probably may have found a solution but i just came across your question and here's my solution...
Below is my code of the getView method of the Adapter class...
@Override
public View getView(int p, View convertView, ViewGroup parent)
{
final ViewHolder holder;
if (convertView == null)
{
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.d_item, null);
holder.dHeading = (TextView) convertView.findViewById(R.id.txt);
holder.ds = (TextView) convertView.findViewById(R.id.txt1);
holder.options = (ImageView)convertView.findViewById(R.id.dPopupMenu);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.dHeading.setText(DList.get(p).getDHeading());
holder.ds.setText(DList.get(p).getDs());
holder.options.setOnClickListener( new OnClickListener()
{
@Override
public void onClick(View v)
{
final PopupMenu popmenu = new PopupMenu(context, holder.options);
popmenu.getMenuInflater().inflate(R.menu.dua_popup_menu, popmenu.getMenu());
popmenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener()
{
public boolean onMenuItemClick(MenuItem item)
{
Toast.makeText(context, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
return true;
}
});
popmenu.show();
}
});
return convertView;
}
You can use ImageView
to display image with 3 dots.
There are two ways for popupmenu
a) Use some layouts and make them visible/gone
b) Use PopupWindow
.
here is sample code for PopupWindow
PopupWindow popupWindow = new PopupWindow(context);
View popUpView = View.inflate(activity, linearlayout, null);
popUpView.setBackgroundColor(Color.TRANSPARENT);
mpopup.setContentView(popUpView);
mpopup.setHeight(LayoutParams.WRAP_CONTENT);
mpopup.setWidth(LayoutParams.WRAP_CONTENT);
mpopup.setFocusable(true);
mpopup.setBackgroundDrawable(activity.getResources().getDrawable(R.drawable.transperent));
mpopup.setOutsideTouchable(true);
mpopup.setAnimationStyle(R.anim.slide_out_up);
mpopup.showAtLocation(popUpView, Gravity.TOP, activity.getResources()
.getInteger(R.integer.log_out_popup_x), activity.getResources()
.getInteger(R.integer.log_out_popup_y));