类android.view.View.OnCreateContextMenuListener源码实例Demo

下面列出了怎么用android.view.View.OnCreateContextMenuListener的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: aedict   文件: AndroidTester.java
/**
 * Opens and activates context menu item for given ListView. Fails if the
 * view does not provide a context menu.
 * 
 * @param view
 *            the view
 * @param menuId
 *            the menu item ID which is to be activated. If the ID was not
 *            assigned then the automatic ID generation is employed,
 *            starting at 10000.
 * @param item
 *            the ListView item ordinal to click.
 */
public void contextMenu(final AbsListView view, final int menuId, final int item) {
	try {
		final Field m = View.class.getDeclaredField("mOnCreateContextMenuListener");
		m.setAccessible(true);
		final OnCreateContextMenuListener listener = (OnCreateContextMenuListener) m.get(view);
		final ContextMenuHandler handler = new ContextMenuHandler();
		final ContextMenu menu = (ContextMenu) Proxy.newProxyInstance(test.getActivity().getClassLoader(), new Class<?>[] { ContextMenu.class }, handler);
		// the trick here is to force the ListView to create context menu on
		// our hacky ContextMenu, which then traces the listeners.
		listener.onCreateContextMenu(menu, null, new AdapterContextMenuInfo(null, item, 0));
		handler.click(menuId);
	} catch (Exception ex) {
		throw new RuntimeException(ex);
	}
}
 
源代码2 项目: styT   文件: FJActivity.java
/**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fj);

        toolbar = (android.support.v7.widget.Toolbar)
                findViewById(R.id.toolbar);
//		初始化Toolbar控件
        setSupportActionBar(toolbar);
        bn_add = (Button) findViewById(R.id.bn_add2);
        bn_clear = (Button) findViewById(R.id.bn_clear2);
        bn_hc = (Button) findViewById(R.id.bn_fj);
        list = (ListView) findViewById(R.id.list2);

        bn_add.setOnClickListener(this);
        bn_clear.setOnClickListener(this);
        bn_hc.setOnClickListener(this);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(THIS_ACTION);
        registerReceiver(br, intentFilter);
        FileList.curpath = Environment.getExternalStorageDirectory().getAbsolutePath();
        //FileList.filter = ".*.gif$";
        FileList.broadcastAction = THIS_ACTION;
        initAdapter();
        sp = PreferenceManager.getDefaultSharedPreferences(this);

        list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(ContextMenu p1, View p2, ContextMenu.ContextMenuInfo p3) {
                // TODO: Implement this method
                p1.add(0, 0, 0, "移除该图片");
            }
        });
    }
 
源代码3 项目: Huochexing12306   文件: MonitorMangAty.java
private void setListViewContextMenuWithDel() {
	lvMang.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
		
		@Override
		public void onCreateContextMenu(ContextMenu menu, View v,
				ContextMenuInfo menuInfo) {
			intCurrDataPos = ((AdapterContextMenuInfo) menuInfo).position;
			menu.add(0, 0, 0, "删除");
		}
	});
}
 
源代码4 项目: Huochexing12306   文件: MonitorMangAty.java
private void setListViewContextMenuWithDel_Resume() {
	lvMang.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
		
		@Override
		public void onCreateContextMenu(ContextMenu menu, View v,
				ContextMenuInfo menuInfo) {
			intCurrDataPos = ((AdapterContextMenuInfo) menuInfo).position;
			menu.add(0, 0, 0, "删除");
			menu.add(0, 1, 1, "恢复所有已暂停车次");
		}
	});
}
 
源代码5 项目: coolreader   文件: BookshelfActivity.java
public void init()   
{
	resolver = getContentResolver();
	bookList = DbDataOperation.getBookInfo(resolver);
	
	lvBookshelf = (ListView)findViewById(R.id.lvBookshelf);
	fileBrowser = (FileBrowser)findViewById(R.id.filebrowser);
	fileBrowser.setOnFileBrowserListener(this);
	lvBookshelf.setOnItemClickListener(this);
	ll=(RelativeLayout)findViewById(R.id.content);
	
	adapter = new CustomAdapter();
	lvBookshelf.setAdapter(adapter);
	lvBookshelf.setOnCreateContextMenuListener(new OnCreateContextMenuListener()
	{
		public void onCreateContextMenu(ContextMenu menu, View v,
				ContextMenuInfo menuInfo)
		{
			AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
			bookPosition = info.position;
			menu.add(Menu.NONE,R.id.menu_open,0,"打开");
			menu.add(Menu.NONE, R.id.menu_del, 1, "删除 " ); 
			menu.add(Menu.NONE, R.id.menu_des, 1, "详细 " ); 
		}
	});
       titleTextV=(TextView)findViewById(R.id.profile_header_title);
       titleTextV.setText("本地文件");
       backImageV=(ImageView)findViewById(R.id.profile_header_back);
       backImageV.setOnClickListener(new OnClickListener(){

               public void onClick(View arg0) {
                   // TODO Auto-generated method stub
                   ll.setVisibility(View.INVISIBLE);
               }
               
           });
}
 
源代码6 项目: coolreader   文件: BookmarkActivity.java
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    lvBookMark = getListView();
    resolver = getContentResolver();
    bookMarks = DbDataOperation.getBookMark(resolver);
    lvBookMark.setBackgroundResource(R.drawable.bg_listview);
    lvBookMark.setAdapter(adapter);
    lvBookMark.setDivider(null);
    lvBookMark.setCacheColorHint(000000);
    lvBookMark.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id)
        {
            currentPosition = position;
            intentToRead();
        }
    });
    lvBookMark.setOnCreateContextMenuListener(new OnCreateContextMenuListener()
    {
        public void onCreateContextMenu(ContextMenu menu, View v,
                ContextMenuInfo menuInfo)
        {
            AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
            currentPosition = info.position;
            menu.add(Menu.NONE,R.id.menu_open,0,"打开");
            menu.add(Menu.NONE, R.id.menu_del, 1, "删除 " ); 
            menu.add(Menu.NONE, R.id.menu_des, 1, "详细 " ); 
  
        }
    });
}
 
源代码7 项目: styT   文件: HCActivity.java
/**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hc);

        toolbar = (android.support.v7.widget.Toolbar)
                findViewById(R.id.toolbar);
//		初始化Toolbar控件
        setSupportActionBar(toolbar);
        bn_add = (Button) findViewById(R.id.bn_add);
        bn_clear = (Button) findViewById(R.id.bn_clear);
        bn_hc = (Button) findViewById(R.id.bn_hc);
        list = (GridView) findViewById(R.id.list);

        bn_add.setOnClickListener(this);
        bn_clear.setOnClickListener(this);
        bn_hc.setOnClickListener(this);
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(THIS_ACTION);
        registerReceiver(br, intentFilter);
        //FileList.curpath = "/mnt/sdcard";
        FileList.curpath = Environment.getExternalStorageDirectory().getAbsolutePath();
        FileList.broadcastAction = THIS_ACTION;
        initAdapter();
        formatter = new SimpleDateFormat("yyyy-MM-dd HH_mm_ss");
        //广告初始化

        sp = PreferenceManager.getDefaultSharedPreferences(this);
        list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(ContextMenu p1, View p2, ContextMenu.ContextMenuInfo p3) {
                // TODO: Implement this method
                //p1.setHeaderTitle("选项");
                //第二个参数是id
                p1.add(0, 0, 0, "设置持续时间");
                p1.add(0, 1, 0, "移除该图片");

            }
        });
    }
 
源代码8 项目: stynico   文件: HCActivity.java
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hc);
	StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary));
	toolbar = (android.support.v7.widget.Toolbar)
	    findViewById(R.id.toolbar);
//		初始化Toolbar控件
	setSupportActionBar(toolbar);
//		用Toolbar取代ActionBar
	//toolbar.setTitleTextColor(getResources().getColor(R.color.text_font_white));//标题颜色
	//	toolbar.setSubtitleTextColor(getResources().getColor(R.color.text_font_white));//副标题颜色


//		设置导航按钮监听
	//overridePendingTransition(R.anim.out_to_right, R.anim.in_from_left);
	bn_add = (Button)findViewById(R.id.bn_add);
	bn_clear = (Button)findViewById(R.id.bn_clear);
	bn_hc = (Button)findViewById(R.id.bn_hc);
	list = (GridView)findViewById(R.id.list);

	bn_add.setOnClickListener(this);
	bn_clear.setOnClickListener(this);
	bn_hc.setOnClickListener(this);
	IntentFilter intentFilter=new IntentFilter();
	intentFilter.addAction(THIS_ACTION);
	registerReceiver(br, intentFilter);
	//FileList.curpath = "/mnt/sdcard";
	FileList.curpath = Environment.getExternalStorageDirectory().getAbsolutePath();
	FileList.broadcastAction = THIS_ACTION;
	initAdapter();
	formatter = new SimpleDateFormat("yyyy-MM-dd HH_mm_ss"); 
	//广告初始化

	sp = PreferenceManager.getDefaultSharedPreferences(this);
	list.setOnCreateContextMenuListener(new OnCreateContextMenuListener(){
		@Override
		public void onCreateContextMenu(ContextMenu p1, View p2, ContextMenu.ContextMenuInfo p3)
		{
		    // TODO: Implement this method
		    //p1.setHeaderTitle("选项");
		    //第二个参数是id
		    p1.add(0, 0, 0, "设置持续时间");
		    p1.add(0, 1, 0, "移除该图片");

		}
	    });
    }
 
源代码9 项目: stynico   文件: FJActivity.java
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
	setContentView(R.layout.fj);
	StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary));
	toolbar = (android.support.v7.widget.Toolbar)
	    findViewById(R.id.toolbar);
//		初始化Toolbar控件
	setSupportActionBar(toolbar);
//		用Toolbar取代ActionBar
	//toolbar.setTitleTextColor(getResources().getColor(R.color.text_font_white));//标题颜色
	//toolbar.setSubtitleTextColor(getResources().getColor(R.color.text_font_white));//副标题颜色



//		设置导航按钮监听
	//overridePendingTransition(R.anim.out_to_right, R.anim.in_from_left);
	bn_add = (Button)findViewById(R.id.bn_add2);
	bn_clear = (Button)findViewById(R.id.bn_clear2);
	bn_hc = (Button)findViewById(R.id.bn_fj);
	list = (ListView)findViewById(R.id.list2);

	bn_add.setOnClickListener(this);
	bn_clear.setOnClickListener(this);
	bn_hc.setOnClickListener(this);
	IntentFilter intentFilter=new IntentFilter();
	intentFilter.addAction(THIS_ACTION);
	registerReceiver(br, intentFilter);
	FileList.curpath = Environment.getExternalStorageDirectory().getAbsolutePath();
	//FileList.filter = ".*.gif$";
	FileList.broadcastAction = THIS_ACTION;
	initAdapter();
	sp = PreferenceManager.getDefaultSharedPreferences(this);

	list.setOnCreateContextMenuListener(new OnCreateContextMenuListener(){
		@Override
		public void onCreateContextMenu(ContextMenu p1, View p2, ContextMenu.ContextMenuInfo p3)
		{
		    // TODO: Implement this method
		    p1.add(0, 0, 0, "移除该图片");
		}
	    });
    }
 
源代码10 项目: Huochexing12306   文件: A6OrderExpandableAdapter.java
@Override
	public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
			ViewGroup parent) {
		if (mLstDatas == null || mLstDatas.size() == 0){
			return null;
		}
		final int groupPos = groupPosition;
		ChildViewHolder holder;
		if (convertView != null){
			holder = (ChildViewHolder) convertView.getTag();
		}else{
			convertView = mInflater.inflate(R.layout.item_a6_order, null);
			holder = new ChildViewHolder();
			holder.slv1 = (SubListView)convertView.findViewById(R.id.item_a6_order_slv1);
			convertView.setTag(holder);
		}
		holder.slv1.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
			
			@Override
			public void onCreateContextMenu(ContextMenu menu, View v,
					ContextMenuInfo menuInfo) {
				mCurrGroupPos = groupPos;
				mCurrChildItemPos = ((AdapterContextMenuInfo) menuInfo).position;
				menu.clear();
				menu.add(A6OrderAty.CONTEXT_GROUP_0, A6OrderAty.CONTEXT_ITEM_ADD_TRAIN_INFO, 0, "添加车次");
				TicketInfo tInfo = mLstDatas.get(groupPos).getTickets().get(mCurrChildItemPos);
				try {
					Date trainDate = TimeUtil.getDTFormat().parse(tInfo.getStart_train_date_page());
					if (trainDate.getTime() >= (new Date()).getTime()){
						if (tInfo.getReturn_flag().equals("Y")){
							//退票
							menu.add(A6OrderAty.CONTEXT_GROUP_0, A6OrderAty.CONTEXT_ITEM_REFUND_TICKET, 1, "退票");
						}
//						if (tInfo.getResign_flag().equals("Y")){
//							//改签
//							menu.add(A6OrderAty.CONTEXT_GROUP_0, A6OrderAty.CONTEXT_ITEM_RESIGN, 2, "改签");
//						}
					}
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
		});
		A6OrderItemAdapter adapter = new A6OrderItemAdapter(mContext, mLstDatas.get(groupPosition).getTickets());
		holder.slv1.setAdapter(adapter);
		return convertView;
	}
 
 类所在包
 类方法
 同包方法