为上下文菜单注册View
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button)findViewById(R.id.button); textView = (TextView)findViewById(R.id.textView); editText = (EditText)findViewById(R.id.editText); registerForContextMenu(textView);
填充上下文菜单
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if(v == textView) { menu.setHeaderTitle("Context Menu"); menu.add(1, 1, 1, "xia"); menu.add(1,2,3,"gegen"); } if(v == button) { menu.setHeaderTitle("button Context Menu"); menu.add(1, 1, 1, "x"); menu.add(1,2,3,"g"); } super.onCreateContextMenu(menu, v, menuInfo); }
响应
public boolean onContextItemSelected(MenuItem item) { // TODO Auto-generated method stub return super.onContextItemSelected(item); }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。