AlertDialog Android "comment" PopupMenu

3

How do I get this result?

The3dotsinthisimagehavealreadybeenpressed.

Mylayout

<android.support.v7.widget.CardViewxmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:layout_margin="3dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/imageComent"
        android:background="@mipmap/ic_perfil"
        android:layout_width="53dp"
        android:layout_height="53dp" />

        <TextView
            android:id="@+id/messageComent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="8dp"
            android:text="comentario"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_below="@+id/nameComent"
            android:layout_toRightOf="@+id/imageComent"
            android:layout_toEndOf="@+id/imageComent" />

        <TextView
            android:id="@+id/nameComent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_toEndOf="@+id/imageComent"
            android:layout_toRightOf="@+id/imageComent"
            android:padding="8dp"
            android:scrollbarAlwaysDrawHorizontalTrack="false"
            android:scrollbarAlwaysDrawVerticalTrack="false"
            android:text="TextView" />

        <ImageView
            android:id="@+id/imageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/messageComent"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="false"
            android:background="@drawable/ic_3pontos"
            android:cropToPadding="false" />
    </RelativeLayout>

</android.support.v7.widget.CardView>

ErrorrelatedtothequestionIhadlater Problem with PopupMenu Recycleradpter

    
asked by anonymous 13.02.2017 / 23:45

1 answer

8

You can create a popup with a list of options using the public class PopupMenu added to Android from level 11 . The PopupMenu will appear below the clicked item if there is space on the screen, or above if there is not. Here is a basic example:

Class

btn = (ImageButton) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //Criando uma instancia do popup
        PopupMenu popup = new PopupMenu(mContext, btn);

        //Inflando o popup usando o arquivo xml
        popup.getMenuInflater().inflate(R.menu.menu_popup, popup.getMenu());

        //Resgata o item clicado e mostra em um Toast
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                Toast.makeText(GetTextFileByURL.this, "Você clicou em : " + item.getTitle(), Toast.LENGTH_SHORT).show();
                return true;
            }
        });
        popup.show();
    }
});

Menu

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/one"
        android:title="Legal"/>
    <item
        android:id="@+id/two"
        android:title="Bom"/>
    <item
        android:id="@+id/three"
        android:title="Ótimo"/>
    <item
        android:id="@+id/four"
        android:title="Espetacular"/>
</menu>

Image

In many cases, a GIF is worth more than 1000 images

    
14.02.2017 / 02:12