`
huakewoniu
  • 浏览: 47763 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Working with Context Menus

阅读更多

                                        Working with Context Menus

 

      Android supports the idea of context menus through an action called a long click.

context menu is represented as a ContextMenu class in the
Android menu architecture.  a context menu is owned by a view, the method to populate context menus  resides in the Activity class. This method is called activity.onCreateContextMenu(),
and its role resembles that of the activity.onCreateOptionsMenu() method.

If you want a particular view
to own a context menu, you must register that view with its activity specifically for the
purpose of owning a context menu. You do this through the
activity.registerForContextMenu(view) method,

 

the steps to implement a context menu:

1. Register a view for a context menu in an activity’s onCreate() method.
2. Populate the context menu using onCreateContextMenu(). You must
complete step 1 before this callback method is invoked by Android.
3. Respond to context-menu clicks.

 

A first step

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView)this.findViewById(R.id.textViewId);
registerForContextMenu(this.getTextView());
}

 

B:Populating a Context Menu

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
menu.setHeaderTitle("Sample Context Menu");
menu.add(200, 200, 200, "item1");
}

C:Responding to Context Menu Items

@Override
public boolean onContextItemSelected(MenuItem item)
{
if (item.itemId() = some-menu-item-id)
{
//handle this menu item
return true;
}
}

分享到:
评论

相关推荐

    Programming Excel With Vba And .net.chm

    Working with Worksheets and Ranges Section 9.1. Work with Worksheet Objects Section 9.2. Worksheets and Worksheet Members Section 9.3. Sheets Members Section 9.4. Work with Outlines Section...

    GWT in Action

    #### Chapter 4: Working with Widgets Widgets are a core component of GWT applications. This chapter examines standard GWT widgets, providing insights into their use within the context of the Dashboard...

    一本android的好书beginning android 2 和 源码

    Menus in Context Taking a Peek Yet More Inflation Menu XML Structure Menu Options and XML Inflating the Menu ■Chapter 12: Fonts Love the One You’re With More Fonts Here a Glyph, There a Glyph ...

    Manning - Eclipse In Action.pdf

    - **Advanced Plug-in Development**: Advanced topics related to plug-in development, including working with preferences, commands, and editors. **Appendices** - **Appendix A: Java Perspective Menu ...

    sciter-sdk-4.0.3.5348

    [context menus] fix of getting focus back, see : https://sciter.com/forums/topic/input/ [win] Fix of crash on ALT+ENTER . [win] fix of "D3DGear bug" – crash when D3DGear is running. cr/lf handling ...

    UE(官方下载)

    Working with Unicode in UltraEdit/UEStudio In this tutorial, we'll cover some of the basics of Unicode-encoded text and Unicode files, and how to view and manipulate it in UltraEdit. Search and delete...

    端口查看工具

    o Fixed bug from version 2.08: Some filters stopped working... * Version 2.08: o Added support for filtering by process ID (In Advanced Filters window), for example: include:process:327 * ...

    Senfore_DragDrop_v4.1

    please read the document "upgrading_to_v4.txt" before you begin working on your existing projects. Note about "Property does not exist" errors: Since all demos were developed with the latest ...

    RxLib控件包内含RxGIF,全部源码及DEMO

    owner-draw menus and much more. 2. The editors of standard properties with some advanced features. TPicture and TGraphic editor adds Copy and Paste Buttons, supports Icons in Clipboard, favorites ...

    Bochs - The cross platform IA-32 (x86) emulator

    - Implemented Process Context ID (PCID) feature - Implemented FS/GS BASE access instructions support (according to document from http://software.intel.com/en-us/avx/) - Rewritten from scratch SMC ...

    Python程序设计(第二版).chm

    Current Working Directory Section 2.8. Command-Line Arguments Section 2.9. Shell Environment Variables Section 2.10. Standard Streams Section 2.11. File Tools Section 2.12. Directory Tools ...

    Tricks of the Windows video Game Programming---part1

    Hungarian Notation........................55 Variable Naming ..................................................................................................58 It All Begins with WinMain()...

    C# Game Programming Cookbook for Unity 3D - 2014

    3.4 User Data Manager (Dealing with Player Stats Such as Health, Lives, etc.)....37 3.4.1 Script Breakdown..........................................39 4. Recipes: Common Components 41 4.1 Introduction...

    Python Power - The Comprehensive Guide (2008).pdf

    CHAPTER 1 About Python ............................................................................................1 What Is Python? ......................................................................

Global site tag (gtag.js) - Google Analytics