Idea on implementing the following pop up menu in ListView

女生的网名这么多〃 提交于 2019-12-03 11:17:21

问题


I would like to have pop up menu, when I click on the 3 dots area in a ListView row.

registerForContextMenu won't meet my need, as it happen during long press, in any area of ListView row.

I would like to know.

  1. How to create a 3 dots looking UI in ListView row?
  2. How to have PopupMenu, even for Android 2.3?

回答1:


  1. You can use ImageView to display image with 3 dots.

  2. 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));



回答2:


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;
}



回答3:


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.



来源:https://stackoverflow.com/questions/18951015/idea-on-implementing-the-following-pop-up-menu-in-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!