registerForContextMenu를 통해 등록된 모든 뷰가 context menu 사용이 가능함.
private final int CONTEXT_MENU_1 = 100;
private void initLayout(String[] items) {
LinearLayout layoutContainer = (LinearLayout) getActivity().findViewById(R.id.linear_container);
layoutContainer.removeAllViews();
for (int i = 0; i < items.size(); i++) {
TextView tv = new TextView(mContext);
tv.setText(item[i]);
tv.setTag(i);
tv.setOnClickListener(mClickListener);
registerForContextMenu(tv);
layoutContainer.addView(tv);
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if(v == null){
return;
}
if(v instanceof TextView){
mSelectedValue = (Integer)v.getTag();
menu.add(0, CONTEXT_MENU_1, 0, R.string.context_menu_1);
}
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getItemId() == CONTEXT_MENU_1){
//Do something
return true;
}
return super.onContextItemSelected(item);
}
'programmer > android' 카테고리의 다른 글
Using TabHost (0) | 2013.07.11 |
---|---|
AlertDialog Message with List(Custom View) (0) | 2013.07.08 |
touch block (0) | 2013.07.08 |
status bar (0) | 2013.07.08 |
highlighting via keyboad (0) | 2013.07.04 |