Idea on implementing the following pop up menu in ListView

后端 未结 3 1705
孤街浪徒
孤街浪徒 2021-02-04 21:34

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

\"enter

相关标签:
3条回答
  • 2021-02-04 22:14

    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.

    0 讨论(0)
  • 2021-02-04 22:17

    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;
    }
    
    0 讨论(0)
  • 2021-02-04 22:35
    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));
    
    0 讨论(0)
提交回复
热议问题