我在主要活动中创建了菜单项,现在我有片段,我想在片段中访问菜单项(如复制、粘贴、共享)。
public class Frag_Angel extends Fragment {
.....
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
wrapper = new LinearLayout(getActivity());
setRetainInstance(true);
v = inflater.inflate(R.layout.frag_angel, wrapper, true);
setHasOptionsMenu(true);
.....
}
我写了下面的代码,但对我不起作用!
public boolean onOptionsItemSelected(android.view.MenuItem item) {
switch (item.getItemId()) {
case R.id.copy:{
refreshList(); // Add a measurement
}
default:
return super.onOptionsItemSelected(item);
}
}
private void refreshList() {
// TODO
Toast.makeText(getActivity(), "Refreshing the first list...",
Toast.LENGTH_SHORT).show();
}
而且我不能使用 getSystemService !