Example usage for android.widget AbsListView CHOICE_MODE_MULTIPLE

List of usage examples for android.widget AbsListView CHOICE_MODE_MULTIPLE

Introduction

In this page you can find the example usage for android.widget AbsListView CHOICE_MODE_MULTIPLE.

Prototype

int CHOICE_MODE_MULTIPLE

To view the source code for android.widget AbsListView CHOICE_MODE_MULTIPLE.

Click Source Link

Document

The list allows multiple choices

Usage

From source file:com.orange.ocara.ui.activity.ResultAuditActivity.java

@AfterViews
void setUpChart() {
    auditChartPager.setAdapter(chartPagerAdapter);
    auditChartChoices.setAdapter(chartChoicesAdapter);

    auditChartChoices.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);

    checkUniqueChoice(0);//from ww  w .ja  v  a 2 s . c  o m

    auditChartPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            checkUniqueChoice(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    auditChartChoices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            // Case of Total
            if (position == 0) {
                chartPagerAdapter.setCustomStat(null);
                auditChartPager.setCurrentItem(0, true);

                checkUniqueChoice(0);
                return;
            }

            final SparseBooleanArray checkedItemPositions = auditChartChoices.getCheckedItemPositions();

            List<Integer> selectedItems = new ArrayList<Integer>();
            for (int i = 0; i < checkedItemPositions.size(); i++) {
                // Item position in adapter
                int pos = checkedItemPositions.keyAt(i);

                if (pos != 0 && checkedItemPositions.valueAt(i)) {
                    selectedItems.add(pos);
                }
            }

            if (selectedItems.isEmpty()) {
                selectedItems.add(0);
            }

            // One choice checked (other than total)
            if (selectedItems.size() == 1) {
                int pos = selectedItems.get(0);

                chartPagerAdapter.setCustomStat(null);
                auditChartPager.setCurrentItem(pos, true);
            } else {
                // Multiple choices, build custom stats
                AccessibilityStats custom = new AccessibilityStats();

                for (int i : selectedItems) {
                    custom.plus(handicapAggregator.getStat(i - 1));
                }

                chartPagerAdapter.setCustomStat(custom);
                auditChartPager.setCurrentItem(0, true);

                auditChartChoices.clearChoices();
                for (int i : selectedItems) {
                    auditChartChoices.setItemChecked(i, true);
                }
            }
        }
    });
}

From source file:org.linphone.ContactsListFragment.java

private void changeContactsAdapter() {

    if (searchCursor != null) {
        searchCursor.close();//  w  w  w. j a v a 2 s  . c o  m
    }

    Cursor allContactsCursor = ContactsManager.getInstance().getAllContactsCursor();
    Cursor sipContactsCursor = ContactsManager.getInstance().getSIPContactsCursor();

    noSipContact.setVisibility(View.GONE);
    noContact.setVisibility(View.GONE);
    contactsList.setVisibility(View.VISIBLE);
    if (onlyDisplayLinphoneContacts) {
        if (sipContactsCursor != null && sipContactsCursor.getCount() == 0) {
            noSipContact.setVisibility(View.VISIBLE);
            contactsList.setVisibility(View.GONE);
        } else if (sipContactsCursor != null) {
            indexer = new AlphabetIndexer(sipContactsCursor,
                    Compatibility.getCursorDisplayNameColumnIndex(sipContactsCursor),
                    " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
            contactsList.setAdapter(
                    new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(), sipContactsCursor));

        }
    } else {
        if (allContactsCursor != null && allContactsCursor.getCount() == 0) {
            noContact.setVisibility(View.VISIBLE);
            contactsList.setVisibility(View.GONE);
        } else if (allContactsCursor != null) {
            indexer = new AlphabetIndexer(allContactsCursor,
                    Compatibility.getCursorDisplayNameColumnIndex(allContactsCursor),
                    " ABCDEFGHIJKLMNOPQRSTUVWXYZ");
            //contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
            List<Contact> allContacts = ContactsManager.getInstance().getAllContacts();
            //               Collections.sort(allContacts, new Comparator<Contact>() {
            //
            //                     /* This comparator will sort AppDetail objects alphabetically. */
            //
            //                  @Override
            //                  public int compare(Contact a1, Contact a2) {
            //                     // String implements Comparable
            //                     return (a1.getName()).compareTo(a2.getName());
            //                  }
            //               });
            contactsList.setAdapter(new ContactsListAdapter(allContacts, allContactsCursor));
        }
    }
    Log.e("list size:" + allContactsCursor.getCount());
    //ContactsManager.getInstance().setLinphoneContactsPrefered(onlyDisplayLinphoneContacts);
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

private void showTagMenu() {
    Set<String> items = new TreeSet<String>();
    items.addAll(m_app.getTaskCache(null).getProjects());
    // Also display contexts in tasks being added
    Task t = new Task(0, textInputField.getText().toString());
    items.addAll(t.getTags());/* ww  w  .  ja  v  a  2  s  . c  o m*/
    final ArrayList<String> projects = Util.sortWithPrefix(items, m_app.sortCaseSensitive(), null);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false);
    builder.setView(view);
    final ListView lv = (ListView) view.findViewById(R.id.listView);
    final EditText ed = (EditText) view.findViewById(R.id.editText);
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice,
            projects.toArray(new String[projects.size()])));
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    m_app.setEditTextHint(ed, R.string.new_tag_name);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ArrayList<String> items = new ArrayList<String>();
            items.addAll(Util.getCheckedItems(lv, true));
            String newText = ed.getText().toString();
            if (!newText.equals("")) {
                items.add(ed.getText().toString());
            }
            for (String item : items) {
                replaceTextAtSelection("+" + item + " ", true);
            }
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog
    AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.project_prompt);
    dialog.show();
}

From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java

/**
 * Enable or disable export mode.//from   w w w.  j av a2 s  .  c om
 *
 * @param exportMode Whether to enable export mode
 * @param animate    Whether to animate the export toolbar
 */
public void setExportMode(boolean exportMode, boolean animate) {
    final ListView listView = getListView();
    if (exportMode) {
        listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    } else {
        setActivateOnItemClick(mTwoPane);
        for (long id : getListView().getCheckedItemIds()) {
            listView.setItemChecked(mAdapter.getItemIndex(id), false);
        }
    }
    mAdapter.setMultiChoiceMode(exportMode);
    listView.setItemChecked(mAdapter.getItemIndex(mActivatedItem), !exportMode && mTwoPane);
    showExportToolbar(exportMode, animate);

    mExportMode = exportMode;
}

From source file:nl.mpcjanssen.simpletask.AddTask.java

private void showContextMenu() {
    Set<String> items = new TreeSet<String>();
    items.addAll(m_app.getTaskCache(this).getContexts());
    // Also display contexts in tasks being added
    Task t = new Task(0, textInputField.getText().toString());
    items.addAll(t.getLists());/*from w ww  .j a  va 2s .co  m*/
    final ArrayList<String> contexts = Util.sortWithPrefix(items, m_app.sortCaseSensitive(), null);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false);
    builder.setView(view);
    final ListView lv = (ListView) view.findViewById(R.id.listView);
    final EditText ed = (EditText) view.findViewById(R.id.editText);
    String[] choices = contexts.toArray(new String[contexts.size()]);
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice, choices));
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    m_app.setEditTextHint(ed, R.string.new_list_name);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ArrayList<String> items = new ArrayList<String>();
            items.addAll(Util.getCheckedItems(lv, true));
            String newText = ed.getText().toString();
            if (!newText.equals("")) {
                items.add(ed.getText().toString());
            }
            for (String item : items) {
                replaceTextAtSelection("@" + item + " ", true);
            }
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog
    AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.context_prompt);
    dialog.show();
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void updateLeftDrawer() {
    TaskCache taskBag = getTaskBag();//from  ww  w  .  j  a v  a 2s .  co m
    ArrayList<String> decoratedContexts = Util.sortWithPrefix(taskBag.getDecoratedContexts(),
            m_app.sortCaseSensitive(), "@-");
    ArrayList<String> decoratedProjects = Util.sortWithPrefix(taskBag.getDecoratedProjects(),
            m_app.sortCaseSensitive(), "+-");
    DrawerAdapter drawerAdapter = new DrawerAdapter(getLayoutInflater(), getString(R.string.context_prompt),
            decoratedContexts, getString(R.string.project_prompt), decoratedProjects);

    m_leftDrawerList.setAdapter(drawerAdapter);
    m_leftDrawerList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    m_leftDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    for (String context : mFilter.getContexts()) {
        int position = drawerAdapter.getIndexOf("@" + context);
        if (position != -1) {
            m_leftDrawerList.setItemChecked(position, true);
        }
    }

    for (String project : mFilter.getProjects()) {
        int position = drawerAdapter.getIndexOf("+" + project);
        if (position != -1) {
            m_leftDrawerList.setItemChecked(position, true);
        }
    }
    m_leftDrawerList.setItemChecked(drawerAdapter.getContextHeaderPosition(), mFilter.getContextsNot());
    m_leftDrawerList.setItemChecked(drawerAdapter.getProjectsHeaderPosition(), mFilter.getProjectsNot());
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void updateLists(@NotNull final List<Task> checkedTasks) {
    final ArrayList<String> contexts = new ArrayList<String>();
    Set<String> selectedContexts = new HashSet<String>();
    final TaskCache taskbag = getTaskBag();
    contexts.addAll(Util.sortWithPrefix(taskbag.getContexts(), m_app.sortCaseSensitive(), null));
    for (Task t : checkedTasks) {
        selectedContexts.addAll(t.getLists());
    }/*from   ww  w .  j ava 2  s  .  c  o  m*/

    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false);
    final ListView lv = (ListView) view.findViewById(R.id.listView);
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice,
            contexts.toArray(new String[contexts.size()])));
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    for (String context : selectedContexts) {
        int position = contexts.indexOf(context);
        if (position != -1) {
            lv.setItemChecked(position, true);
        }
    }

    final EditText ed = (EditText) view.findViewById(R.id.editText);
    m_app.setEditTextHint(ed, R.string.new_list_name);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(view);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ArrayList<String> originalLines = new ArrayList<String>();
            originalLines.addAll(Util.tasksToString(getCheckedTasks()));
            ArrayList<String> items = new ArrayList<String>();
            ArrayList<String> uncheckedItesm = new ArrayList<String>();
            uncheckedItesm.addAll(Util.getCheckedItems(lv, false));
            items.addAll(Util.getCheckedItems(lv, true));
            String newText = ed.getText().toString();
            if (!newText.equals("")) {
                items.add(ed.getText().toString());
            }
            for (String item : items) {
                for (Task t : checkedTasks) {
                    t.addList(item);
                }
            }
            for (String item : uncheckedItesm) {
                for (Task t : checkedTasks) {
                    t.removeTag("@" + item);
                }
            }
            finishActionmode();
            m_app.getTaskCache(null).modify(originalLines, checkedTasks, null, null);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog
    AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.update_lists);
    dialog.show();
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void updateTags(@NotNull final List<Task> checkedTasks) {
    final ArrayList<String> projects = new ArrayList<String>();
    Set<String> selectedProjects = new HashSet<String>();
    final TaskCache taskbag = getTaskBag();
    projects.addAll(Util.sortWithPrefix(taskbag.getProjects(), m_app.sortCaseSensitive(), null));
    for (Task t : checkedTasks) {
        selectedProjects.addAll(t.getTags());
    }/*from  w  ww.  j ava2 s. c o m*/

    @SuppressLint("InflateParams")
    View view = getLayoutInflater().inflate(R.layout.tag_dialog, null, false);
    final ListView lv = (ListView) view.findViewById(R.id.listView);
    lv.setAdapter(new ArrayAdapter<String>(this, R.layout.simple_list_item_multiple_choice,
            projects.toArray(new String[projects.size()])));
    lv.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    for (String context : selectedProjects) {
        int position = projects.indexOf(context);
        if (position != -1) {
            lv.setItemChecked(position, true);
        }
    }

    final EditText ed = (EditText) view.findViewById(R.id.editText);
    m_app.setEditTextHint(ed, R.string.new_tag_name);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(view);

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ArrayList<String> items = new ArrayList<String>();
            ArrayList<String> originalLines = new ArrayList<String>();
            originalLines.addAll(Util.tasksToString(checkedTasks));
            ArrayList<String> uncheckedItems = new ArrayList<String>();
            uncheckedItems.addAll(Util.getCheckedItems(lv, false));
            items.addAll(Util.getCheckedItems(lv, true));
            String newText = ed.getText().toString();
            if (!newText.equals("")) {
                items.add(ed.getText().toString());
            }
            for (String item : items) {
                for (Task t : checkedTasks) {
                    t.addTag(item);
                }
            }
            for (String item : uncheckedItems) {
                for (Task t : checkedTasks) {
                    t.removeTag("+" + item);
                }
            }
            finishActionmode();
            m_app.getTaskCache(null).modify(originalLines, checkedTasks, null, null);
        }
    });
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // User cancelled the dialog
        }
    });
    // Create the AlertDialog
    AlertDialog dialog = builder.create();
    dialog.setTitle(R.string.update_tags);
    dialog.show();
}