Пример #1
0
  /**
   * Toggle the selection state of an item.
   *
   * <p>If the item was the last one in the selection and is unselected, the selection is stopped.
   * Note that the selection must already be started (actionMode must not be null).
   *
   * @param position Position of the item to toggle the selection state
   */
  private void toggleSelection(int position) {
    chatAdapter.toggleSelection(position);
    int count = chatAdapter.getSelectedItemCount();

    if (count == 0) {
      actionMode.finish();
    } else {
      actionMode.setTitle(String.valueOf(count));
      actionMode.invalidate();
    }
  }
Пример #2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    switch (id) {
      case android.R.id.home:
        onBackPressed();
        return true;

      case R.id.action_clearChat:
        // Limpando as mensagens no banco de dados
        messageDAO.limparConversa(mNumeroChatAtivo);
        // Limpando a lista
        chatAdapter.clearItemList();
        // Ativando o textview com a mensagem
        findViewById(R.id.empty).setVisibility(View.VISIBLE);
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
Пример #3
0
 @Override
 public void onClickListener(View view, int position) {
   if (actionMode != null) {
     toggleSelection(position);
   } else {
     chatAdapter.removeItem(position);
   }
 }