2013-10-06 2 views
1

longClick()에서 다중보기 선택을 사용 가능하게하려고합니다. 액션 모드 객체를 선언하고 startActionMode()를 호출해야합니까? 또한 단일 항목 클릭에 대한 메뉴 목록을 어떻게 변경합니까? 표시된대로 설명서를 참조로 사용했습니다.배치 상황 별 동작 모드

ListView listView = getListView(); 
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); 
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() { 

@Override 
public void onItemCheckedStateChanged(ActionMode mode, int position, 
             long id, boolean checked) { 
    // Here you can do something when items are selected/de-selected, 
    // such as update the title in the CAB 
} 

@Override 
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 
    // Respond to clicks on the actions in the CAB 
    switch (item.getItemId()) { 
     case R.id.menu_delete: 
      deleteSelectedItems(); 
      mode.finish(); // Action picked, so close the CAB 
      return true; 
     default: 
      return false; 
    } 
} 

@Override 
public boolean onCreateActionMode(ActionMode mode, Menu menu) { 
    // Inflate the menu for the CAB 
    MenuInflater inflater = mode.getMenuInflater(); 
    inflater.inflate(R.menu.context, menu); 
    return true; 
} 

@Override 
public void onDestroyActionMode(ActionMode mode) { 
    // Here you can make any necessary updates to the activity when 
    // the CAB is removed. By default, selected items are deselected/unchecked. 
} 

@Override 
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 
    // Here you can perform updates to the CAB due to 
    // an invalidate() request 
    return false; 
} 

});

답변

2

다음은 단일 항목 클릭에 대한 메뉴 목록을 변경하는 코드입니다.

@Override 
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 
if (selCount == 1){ 
    //show the menu here that you want if only 1 item is selected 
} else { 
    //show the menu here that you want if more than 1 item is selected 
     } 
} 
+0

감사를 다음과 같이

int count=0; @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { if (checked) { count++; } else { count--; } mode.invalidate(); // Add this to Invalidate CAB so that it calls onPrepareActionMode } 

이제 onPrepareActionMode을 수정할 수 있지만 이것은 내가) startActionMode (전화 어떻게? – Meenakshi

+0

mActionMode = new UniversityList(). startActionMode (multichoice) 여기서 mActionMode는 ActionMode 객체이고 multichoice는 MultiChoiceModeListener 객체입니다. – Meenakshi

관련 문제