0

では無視されます。私が取り組んでいる唯一の問題は、アイテムの最初の長いクリックは無視され、2回目のクリック以降はCABが表示されることです。まず長いクリックは、私は、ユーザーが長い項目をクリックすると、コンテキストアクションバー(CAB)を示し、ユーザーが複数の項目を選択でき、リストビューを構築しようとしているリストビュー

マイコード:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_notification_list); 
    mLv = (ListView) findViewById(R.id.listview_notifications); 
    mCtx = this; 

    ... 

    mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { 
      final CustomNotification notification = (CustomNotification) mAdapter.getItem(position); 
      new AlertDialog.Builder(NotificationListActivity.this) 
        .setTitle(notification.getScope()) 
        .setMessage(notification.getMessage()) 
        .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { 
         @Override 
         public void onClick(DialogInterface dialog, int which) { 
          if(notification.getReadDate().isEmpty()){ 
           //Mark local notification as read 
           ContentResolver cr = getContentResolver(); 
           DateTime dateTime = new DateTime(DateTimeZone.getDefault()); 
           ContentValues values = new ContentValues(); 
           values.put(CustomNotification.COL_READ_DATE, dateTime.toString()); 

           String selection = CustomNotification.COL_NOTIFICATION_ID + "=" + notification.getNotificationID(); 
           cr.update(CustomNotification.getContentUri(), values, selection, null); 

           Intent i = new Intent(Constants.BROADCAST_GCM_SINGLE_NOTIFICATION_READ); 
           sendBroadcast(i); 
          } 
          dialog.dismiss(); 
         } 
        }) 
        .create() 
        .show(); 
     } 
    }); 

    mLv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { 
     @Override 
     public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { 
      mLv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); 
      mLv.setMultiChoiceModeListener(new modeCallBack()); 
      return true; 
     } 
    }); 

    mLv.setEmptyView(findViewById(R.id.notification_listview_empty)); 
} 

マイMultiChoiceListener実装:

private class modeCallBack implements ListView.MultiChoiceModeListener{ 

     @Override 
     public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { 
      if(checked){ 
       mAdapter.addSelectedItem((CustomNotification) notificationArray.get(position)); 
      }else{ 
       mAdapter.removeSelectedItem((CustomNotification) notificationArray.get(position)); 
      } 
      mAdapter.notifyDataSetChanged(); 
     } 

     @Override 
     public boolean onCreateActionMode(ActionMode mode, Menu menu) { 
      mAdapter.setActionMode(mode); 
      mode.getMenuInflater().inflate(R.menu.notifications_selected_actions, menu); 
      return true; 
     } 

     @Override 
     public boolean onPrepareActionMode(ActionMode mode, Menu menu) { 
      return true; 
     } 

     @Override 
     public boolean onActionItemClicked(ActionMode mode, MenuItem item) { 
      return false; 
     } 

     @Override 
     public void onDestroyActionMode(ActionMode mode) { 
      mAdapter.setActionMode(null); 
      mAdapter.removeAllSelectedItems(); 
     } 
} 

答えて

3
 mLv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); 
    mLv.setMultiChoiceModeListener(new modeCallBack()); 

この2つのラインは、長いクリックを面倒にする必要があります。これが最初のLongClickを無視した主な理由です。

+0

それは、ありがとう、それをしました。 – Anubis

1

private modeCallback mModeCallback = new modeCallback(); 

そして

mLv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { 
    @Override 
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { 
     mLv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); 
     mLv.setMultiChoiceModeListener(mModeCallBack); 
     return true; 
    } 
}); 
を宣言

理由は、最初のLongClickでは、実際にコールするのではなくコールバックを設定しているからです。