1
할 일 목록을 개발 중입니다. 이 응용 프로그램에서 할 일 항목은 목록 항목으로 목록보기에 추가됩니다. 각 목록 항목 (각 할 일 항목에 해당)은 여러 개의보기 요소가있는 상대적 레이아웃을가집니다. 이 목록보기에 대한 컨텍스트 메뉴를 등록했습니다. 그러나 문제는 목록 항목을 길게 누르면 해제되지 않는다는 것입니다. 다음은 코드 블록입니다. (할 일 항목을 보여주는 목록보기) ...목록보기에서 복합 목록 항목에 대한 컨텍스트 메뉴가 실행되지 않았습니다.
목록의 활동을 도와주세요 :
공용 클래스 ToDoManagerActivity는 ListActivity {
private static final int ADD_TODO_ITEM_REQUEST = 0;
private static final String FILE_NAME = "myToDos.txt";
private static final String TAG = "Lab-UserInterface";
// IDs for menu items
private static final int MENU_DELETE = Menu.FIRST;
private static final int MENU_DUMP = Menu.FIRST + 1;
private static final int MENU_ADD = Menu.FIRST + 2;
ToDoListAdapter mAdapter;
TextView footerView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create a new TodoListAdapter for this ListActivity's ListView
mAdapter = new ToDoListAdapter(getApplicationContext());
// TODO - Attach the adapter to this ListActivity's ListView
getListView().setAdapter(mAdapter);
// register for context menu
registerForContextMenu(getCurrentFocus());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater contextMenu = getMenuInflater();
contextMenu.inflate(R.menu.menu_context, menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, MENU_DELETE, Menu.NONE, "Delete all");
menu.add(Menu.NONE, MENU_DUMP, Menu.NONE, "Dump to log");
menu.add(Menu.NONE, MENU_ADD, Menu.NONE, "Add ToDo");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_DELETE:
mAdapter.clear();
return true;
case MENU_DUMP:
dump();
return true;
case MENU_ADD:
Intent mAddToDo = new Intent(ToDoManagerActivity.this,
AddToDoActivity.class);
startActivityForResult(mAddToDo, ADD_TODO_ITEM_REQUEST);
return true;
default:
return super.onOptionsItemSelected(item);
}
}} 목록 항목의 레이아웃과 같다
를 확장 다음과 같습니다 :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/titleView"
android:textColor="#000000"
android:textStyle="italic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceLarge" >
</TextView>
<TextView
android:id="@+id/StatusLabel"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/statusCheckBox"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="17dp"
android:text="@string/done_string" >
</TextView>
<CheckBox
android:id="@+id/statusCheckBox"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="52dp"
android:layout_toRightOf="@+id/StatusLabel" >
</CheckBox>
<TextView
android:id="@+id/PriorityLabel"
android:textColor="#000000"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/statusCheckBox"
android:layout_alignTop="@+id/StatusLabel"
android:layout_toLeftOf="@+id/priorityView"
android:text="@string/priority_string" >
</TextView>
<TextView
android:id="@+id/priorityView"
android:textColor="#000000"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/statusCheckBox"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/StatusLabel" >
</TextView>
<TextView
android:id="@+id/DateLabel"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/statusCheckBox"
android:text="@string/date_string" >
</TextView>
<TextView
android:id="@+id/dateView"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/DateLabel"
android:layout_toRightOf="@+id/DateLabel" >
</TextView>
</RelativeLayout>
컨텍스트 메뉴 xml은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/rajit_me"
android:title="Rajit"/>
<item
android:id="@+id/mou_me"
android:title="Mou"/>
<item
android:id="@+id/suha_me"
android:title="Suha"/>
<item
android:id="@+id/samah_me"
android:title="samah"/>
</menu>