Alertdialog Android "comment" Popupmenu

Asked

Viewed 175 times

3

How do I get this result

inserir a descrição da imagem aqui

the 3 dots on this image have already been pressed.

My layout

<android.support.v7.widget.CardView xmlns: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>

inserir a descrição da imagem aqui

Error related to question I later had Problem with Recycleradpter Popupmenu

  • Did I get it. You want to show the popup with a list of right options?

1 answer

8


It is possible to create a popup with a list of options using the public class PopupMenu added to Android from the level 11. The PopupMenu appear below the clicked item if there is space on the screen, or above if there is no. See below 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>

Imagery

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

inserir a descrição da imagem aqui

  • exactly what I want, tomorrow I put in practice, thank you!

  • I’m having trouble with the context, because I’m using Recyclerview ,Recycleradapter.

  • @Wallaceroberto this works independently whether it’s Recyclerview or not. Maybe you’re having another problem. If you want to create another question is fine. You know.

  • http://answall.com/questions/184083/problema-com-popupmenu-recycleradpter

  • My new question, thanks in advance :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.