13-7-30 上下文菜单(contextMenu)
来源:互联网 发布:手机主板测试软件 编辑:程序博客网 时间:2024/06/03 15:56
上下文菜单(Context Menu)是android.View.Menu的子类,它提供了菜单的设计接口。
官方提供的方法有:
Clears the header of the context menu.
Sets the context menu header's icon to the icon given in icon
Drawable
.Sets the context menu header's icon to the icon given in iconRes resource id.
Sets the context menu header's title to the title given in title.
Sets the context menu header's title to the title given in titleRes resource identifier.
Sets the header of the context menu to the
View
given in view.下面我将做一个单击listView中的item调出ContextMenu,实现:删除、复制、分享到微博,的menu
其中比较关键的一点就是如何通过listView中的item进行注册ContextMenu,代码很少如下:
private void msg_opearte(){listMsg.setOnItemClickListener(new OnItemClickListener(){@Overridepublic void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) {// TODO Auto-generated method stub/*TextView txt = (TextView)arg1.findViewById(R.id.chatting_content_itv);msg = txt.getText().toString();Cursor cursor_msg = sqlMsg.findAll();cursor_msg.moveToFirst();cursor_msg.move(arg2-1);Log.i(TAG, arg2+"");msg_position = cursor_msg.getInt(0);Log.i(TAG,"-------->>>>"+msg_position);*/registerForContextMenu(arg0);}});}@Overridepublic void onCreateContextMenu(ContextMenu menu, View V, ContextMenuInfo menuInfo){//添加菜单选项menu.add(0, 1, 0, "删除消息");menu.add(0, 2, 0, "复制消息");menu.add(0, 3, 0, "分享到微博");}@Overridepublic boolean onContextItemSelected(MenuItem item){//添加选项处理switch(item.getItemId()){case 1:sqlMsg.delete(msg_position);refresh_msg();break;case 2:ClipboardManager clip = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); clip.setText(msg); // 复制 break;case 3:break;}return true;}
- 13-7-30 上下文菜单(contextMenu)
- 上下文菜单(ContextMenu)
- ContextMenu上下文菜单
- 使用上下文菜单ContextMenu
- 上下文菜单ContextMenu
- Android--ContextMenu上下文菜单
- 【Android】上下文菜单contextMenu
- ContextMenu(上下文菜单)
- ContextMenu上下文菜单
- ContextMenu上下文菜单
- ContextMenu上下文菜单
- Contextmenu上下文菜单
- Android上下文菜单 ContextMenu
- Android-ContextMenu上下文菜单
- 使用上下文菜单ContextMenu
- ContextMenu---上下文菜单
- ContextMenu上下文菜单
- 上下文菜单ContextMenu
- 2.3线性表的链式表示和实现
- ERP系统容灾方案典型架构
- 【7gyy】笔者支招:win7电脑如何升级win8系统
- LINUX 信号机制
- 百度地图api之如何自定义标注图标
- 13-7-30 上下文菜单(contextMenu)
- Android的数据存取
- 制作 ramdisk.img,使用cpio 和 gzip
- (总结)STM32关于可编程电压检测器的运用
- fortran基础
- 文件过滤器
- Blender及其游戏引擎
- WPF学习开拔
- 1058. A+B in Hogwarts (20)- PAT