Example usage for android.widget ListView setChoiceMode

List of usage examples for android.widget ListView setChoiceMode

Introduction

In this page you can find the example usage for android.widget ListView setChoiceMode.

Prototype

public void setChoiceMode(int choiceMode) 

Source Link

Document

Defines the choice behavior for the List.

Usage

From source file:com.checktipsplitter.wizard.ui.ReviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page, container, false);

    TextView titleView = (TextView) rootView.findViewById(android.R.id.title);
    titleView.setText(R.string.review_title);
    titleView.setTextColor(getResources().getColor(R.color.review_green));

    ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(mReviewAdapter);/*from   w  w  w .  jav a  2 s. com*/
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    return rootView;
}

From source file:com.btmura.android.reddit.app.ThingListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = super.onCreateView(inflater, container, savedInstanceState);
    ListView lv = (ListView) v.findViewById(android.R.id.list);
    lv.setVerticalScrollBarEnabled(false);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    lv.setMultiChoiceModeListener(this);

    SwipeDismissTouchListener touchListener = new SwipeDismissTouchListener(lv, this);
    lv.setOnTouchListener(touchListener);

    ThumbnailLoader.lock(false);//from www.jav a 2  s  . c  om
    final OnScrollListener scrollListener = touchListener.makeScrollListener();
    lv.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScroll(AbsListView lv, int firstVisible, int visibleCount, int totalCount) {
            scrollListener.onScroll(lv, firstVisible, visibleCount, totalCount);
            ThingListFragment.this.onScroll(lv, firstVisible, visibleCount, totalCount);
        }

        @Override
        public void onScrollStateChanged(AbsListView lv, int scrollState) {
            scrollListener.onScrollStateChanged(lv, scrollState);
            ThingListFragment.this.onScrollStateChanged(lv, scrollState);
        }
    });

    return v;
}

From source file:de.bennir.DVBViewerController.wizard.ui.SingleChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page, container, false);

    String title = null;/*from   w  ww  .  ja va  2 s .c  om*/
    try {
        title = getString(getResources().getIdentifier(mKey, "string", "de.bennir.DVBViewerController"));
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (title == null)
        ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
    else
        ((TextView) rootView.findViewById(android.R.id.title)).setText(title);

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    // Pre-select currently selected item.
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY);
            for (int i = 0; i < mChoices.size(); i++) {
                if (mChoices.get(i).equals(selection)) {
                    listView.setItemChecked(i, true);
                    break;
                }
            }
        }
    });

    return rootView;
}

From source file:br.com.hojeti.wizardpager.ui.MultipleChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    // Pre-select currently selected items.
    new Handler().post(new Runnable() {
        @Override/* www .  j a  v a2  s  .c o m*/
        public void run() {
            ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY);
            if (selectedItems == null || selectedItems.size() == 0) {
                return;
            }

            Set<String> selectedSet = new HashSet<String>(selectedItems);

            for (int i = 0; i < mChoices.size(); i++) {
                if (selectedSet.contains(mChoices.get(i))) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    });

    return rootView;
}

From source file:net.i2p.android.wizard.ui.MultipleChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_wizard_page, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    // Pre-select currently selected items.
    new Handler().post(new Runnable() {
        public void run() {
            ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY);
            if (selectedItems == null || selectedItems.size() == 0) {
                return;
            }//from  w w  w  . jav a  2 s .co m

            Set<String> selectedSet = new HashSet<String>(selectedItems);

            for (int i = 0; i < mChoices.size(); i++) {
                if (selectedSet.contains(mChoices.get(i))) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    });

    return rootView;
}

From source file:wizard.ui.MultipleChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.add_balance_fragment_page, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    // Pre-select currently selected items.
    new Handler().post(new Runnable() {
        @Override/*from ww  w.  j  ava2 s  . co m*/
        public void run() {
            ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY);
            if (selectedItems == null || selectedItems.size() == 0) {
                return;
            }

            Set<String> selectedSet = new HashSet<String>(selectedItems);

            for (int i = 0; i < mChoices.size(); i++) {
                if (selectedSet.contains(mChoices.get(i))) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    });

    return rootView;
}

From source file:com.grottworkshop.gwswizardpager.ui.MultipleChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_multiple_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    // Pre-select currently selected items.
    new Handler().post(new Runnable() {
        @Override/*w  ww.  j  av a  2 s. c om*/
        public void run() {
            ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY);
            if (selectedItems == null || selectedItems.size() == 0) {
                return;
            }

            Set<String> selectedSet = new HashSet<>(selectedItems);

            for (int i = 0; i < mChoices.size(); i++) {
                if (selectedSet.contains(mChoices.get(i))) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    });

    return rootView;
}

From source file:ni.org.ics.estudios.appmovil.wizard.ui.SingleChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page, container, false);

    mTitleTextInput = (TextView) rootView.findViewById(android.R.id.title);
    mTitleTextInput.setText(mPage.getTitle());
    if (!mPage.ismEnabled()) {
        mTitleTextInput.setTextColor(Color.GRAY);
    } else {//from   w  w  w . j  a  v a  2 s.  c om
        mTitleTextInput.setTextColor(Color.parseColor(mPage.getTextColor()));
    }
    mHintTextInput = (TextView) rootView.findViewById(R.id.label_hint);
    mHintTextInput.setText(mPage.getHint());
    mHintTextInput.setTextColor(Color.parseColor(mPage.getmHintTextColor()));

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    listView.setEnabled(mPage.ismEnabled());

    // Pre-select currently selected item.
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY);
            for (int i = 0; i < mChoices.size(); i++) {
                if (mChoices.get(i).equals(selection)) {
                    listView.setItemChecked(i, true);
                    break;
                }
            }
        }
    });

    return rootView;
}

From source file:com.jhk.whysoformal.activity.musiclist.fragment.MusicListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = super.onCreateView(inflater, container, savedInstanceState);

    ListView listView = (ListView) view.findViewById(android.R.id.list);

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {
        @Override// w  ww  .  ja  v  a2s .  c  om
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
        }

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

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

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
        }
    });

    return view;
}

From source file:com.sharpcart.android.wizardpager.wizard.ui.MultipleChoiceFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_page, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);

    // Pre-select currently selected items.
    new Handler().post(new Runnable() {
        @Override//ww w. java 2  s .co m
        public void run() {
            final ArrayList<String> selectedItems = mPage.getData().getStringArrayList(Page.SIMPLE_DATA_KEY);
            if (selectedItems == null || selectedItems.size() == 0) {
                return;
            }

            final Set<String> selectedSet = new HashSet<String>(selectedItems);

            for (int i = 0; i < mChoices.size(); i++) {
                if (selectedSet.contains(mChoices.get(i))) {
                    listView.setItemChecked(i, true);
                }
            }
        }
    });

    return rootView;
}