public class AndroidTest extends Activity {
protected static final int ENTRY_ADD = Menu.FIRST;
protected static final int ENTRY_REMOVE = Menu.FIRST + 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Dialog);
ListView lv = new ListView(this);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.test, android.R.layout.simple_list_item_1);
lv.setAdapter(adapter);
lv.setCacheColorHint(0);
lv.setOnCreateContextMenuListener(new OnCreateContextMenuListener ()
{
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.add(0, ENTRY_ADD, 1, "Add");
menu.add(0, ENTRY_REMOVE , 2,"Remove");
}});
//Dialog d = new Dialog(this);
//d.setContentView(lv);
//d.show();
setContentView(lv);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info =
(AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
Log.d("Test", "Selected item " + info.position);
switch(item.getItemId()) {
case ENTRY_ADD:
Log.d("Test", "Add was clicked");
break;
case ENTRY_REMOVE:
Log.d("Test", "Remove was clicked");
break;
default:
return super.onContextItemSelected(item);
}
return true;
}
'android programming' 카테고리의 다른 글
http에 request요청시... redirect 하는 방법... (0) | 2010.03.05 |
---|---|
문자코드변환 (0) | 2010.03.04 |
팝업창(Dialog) (0) | 2010.01.24 |
가상키패드 (0) | 2010.01.24 |
Context? (0) | 2010.01.24 |