android.view.View.OnCreateContextMenuListener Java Examples
The following examples show how to use
android.view.View.OnCreateContextMenuListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidTester.java From aedict with GNU General Public License v3.0 | 6 votes |
/** * 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); } }
Example #2
Source File: FJActivity.java From styT with Apache License 2.0 | 5 votes |
/** * 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, "移除该图片"); } }); }
Example #3
Source File: MonitorMangAty.java From Huochexing12306 with Apache License 2.0 | 5 votes |
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, "删除"); } }); }
Example #4
Source File: MonitorMangAty.java From Huochexing12306 with Apache License 2.0 | 5 votes |
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, "恢复所有已暂停车次"); } }); }
Example #5
Source File: BookshelfActivity.java From coolreader with MIT License | 5 votes |
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); } }); }
Example #6
Source File: BookmarkActivity.java From coolreader with MIT License | 5 votes |
@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, "详细 " ); } }); }
Example #7
Source File: HCActivity.java From styT with Apache License 2.0 | 4 votes |
/** * 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, "移除该图片"); } }); }
Example #8
Source File: HCActivity.java From stynico with MIT License | 4 votes |
/** 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, "移除该图片"); } }); }
Example #9
Source File: FJActivity.java From stynico with MIT License | 4 votes |
/** 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, "移除该图片"); } }); }
Example #10
Source File: A6OrderExpandableAdapter.java From Huochexing12306 with Apache License 2.0 | 4 votes |
@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; }