就像在Play Store应用程序中一样,我们可以看到应用程序的磁贴排列在水平网格视图中。他们是怎么做到的?
简单,GridView磁贴包含ImageView,TextView和一个按钮(可能是一个ImageView),它看起来像是在其他应用程序中看到的菜单按钮。单击它,我们可以看到弹出一个上下文菜单,其中包含安装该应用程序的选项。我可以像他们一样设置一切,但不能在BaseAdapter中使用registerForContextMenu。请帮帮我。
编辑:
@Override public View getView(int position, View convertView, ViewGroup parent)
{ LayoutInflater l = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = l.inflate(R.layout.flowadapter,null);
TextView t = (TextView)v.findViewById(R.id.textView10);
TextView t2 = (TextView)v.findViewById(R.id.textView7);
ImageView im = (ImageView)v.findViewById(R.id.imageButton7);
c.registerForContextMenu(im);
String s = arr.get(position);
t.setText(s);
error on c.registerForContextMenu(im);
发布于 2016-01-07 16:12:18
播放商店正在使用单击溢出图标时显示的PopupMenu。您可以找到教程here。
发布于 2016-01-07 16:41:03
在你的活动中尝试下面的代码,而不是在扩展基本适配器的类中,我正在我的应用程序中使用这种方式。
yourGridView.setOnItemClickListener(new AdapterView.OnItemClickListener(){ @Override public void onItemClick(AdapterView父节点,视图视图,整型位置,长id) { registerForContextMenu(yourGridView);} });
这会帮到你的。如果您想在Textview中获得您所单击的特定项目的文本,可以添加String string = t.getText().toString();在您的on中单击listner。
https://stackoverflow.com/questions/34649985
复制相似问题