获取的PopupMenu的情况下像文本菜单 [英] Get context of PopupMenu like ContextMenu

查看:120
本文介绍了获取的PopupMenu的情况下像文本菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我的 ExpandableListView 已被定义如下组行:

So my ExpandableListView has group rows that are defined like :

group_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/GroupName"
        style="@style/ListViewRowStyle"
        android:paddingLeft="40dp"
        android:textSize="18sp" >
    </TextView>

    <ImageView
        android:id="@+id/Menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="10dp"
        android:contentDescription="@string/default_content_description_text"
        android:src="@drawable/ic_menu_moreoverflow_normal_holo_light" >
    </ImageView>

</RelativeLayout> 

当你点击的TextView 将展开或折叠根据当前是否被显示的子行。我附上一个 OnClickListener 的ImageView 组一行。当此的ImageView 点击我推出了的PopupMenu 像下面的图片:

When you click on the TextView it will expand or collapse depending on whether or not the child rows are currently displayed. I have attached an OnClickListener to the ImageView in the group row. When this ImageView is clicked I launch a PopupMenu like the images below :

一旦的PopupMenu 显示和点击的行动之一,我想该组的所有子执行的操作。问题是,我不能确定,其中的ImageView 被点击的行。

Once the PopupMenu is displayed and one of the actions is clicked, I would like to perform an action on all children of the group. The problem is that I cannot determine the row in which the ImageView was clicked.

我已经找到了如何将动作适用于所有孩子中唯一的方法是使用文本菜单像下面的图片:

The only way I have figured out how to apply an action to all children is with a ContextMenu like the image below :

我要避免使用文本菜单因为LongClick一组排可能不是很明显的用户弄清楚,它会带来一些行动,以执行对孩子们行。我觉得比较明显的设计是为了锚定的PopupMenu 的ImageView (在我的情况下,菜单图标),并有的动作被应用到孩子的行该组的。我怎样才能得到这个功能与的PopupMenu

I want to avoid using a ContextMenu because a LongClick on a group row may not be obvious for a user to figure out that it would bring up some actions to perform on the children rows. I think the more obvious design is to anchor a PopupMenu to an ImageView (in my case a menu icon) and have the action be applied to the children rows of that group. How can I get this functionality with a PopupMenu ?

推荐答案

所以我想通了其中的菜单图标,为了有一定的范围内被点击,我利用了的 setTag()和的 getTag()中的查看类的方法而只是应用这些方法的的ImageView (菜单图标)。

So I figured out that in order to have some context of which menu icon was clicked, I utilized the setTag() and getTag() methods of the View class and just applied these methods to the ImageView (menu icon).

这篇关于获取的PopupMenu的情况下像文本菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆