Example usage for android.widget AbsListView CHOICE_MODE_SINGLE

List of usage examples for android.widget AbsListView CHOICE_MODE_SINGLE

Introduction

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

Prototype

int CHOICE_MODE_SINGLE

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

Click Source Link

Document

The list allows up to one choice

Usage

From source file:com.adstrosoftware.gpsplayground.FeatureListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice,
            getResources().getStringArray(R.array.featureArray)));
}

From source file:at.bitfire.davdroid.ui.AccountListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getLoaderManager().initLoader(0, getArguments(), this);

    ListView list = getListView();
    list.setOnItemClickListener(this);
    list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
}

From source file:com.github.walterfan.gtd.ui.HeadlinesFragment.java

@Override
public void onStart() {
    super.onStart();

    // When in two-pane layout, set the listview to highlight the selected list item
    // (We do this during onStart because at the point the listview is available.)
    if (getFragmentManager().findFragmentById(R.id.article_fragment) != null) {
        getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    }/*from   ww  w .java 2  s.c  o m*/
}

From source file:com.sagar.sunshine.ItemChoiceManager.java

public void onClick(RecyclerView.ViewHolder vh) {
    if (mChoiceMode == AbsListView.CHOICE_MODE_NONE)
        return;//w ww.  j a  v a  2s.c  o m

    int checkedItemCount = mCheckStates.size();
    int position = vh.getAdapterPosition();

    if (position == RecyclerView.NO_POSITION) {
        Log.d(LOG_TAG, "Unable to Set Item State");
        return;
    }

    switch (mChoiceMode) {
    case AbsListView.CHOICE_MODE_NONE:
        break;
    case AbsListView.CHOICE_MODE_SINGLE: {
        boolean checked = mCheckStates.get(position, false);
        if (!checked) {
            for (int i = 0; i < checkedItemCount; i++) {
                mAdapter.notifyItemChanged(mCheckStates.keyAt(i));
            }
            mCheckStates.clear();
            mCheckStates.put(position, true);
            mCheckedIdStates.clear();
            mCheckedIdStates.put(mAdapter.getItemId(position), position);
        }
        mAdapter.onBindViewHolder(vh, position);
        break;
    }
    case AbsListView.CHOICE_MODE_MULTIPLE: {
        boolean checked = mCheckStates.get(position, false);
        mCheckStates.put(position, !checked);
        mAdapter.onBindViewHolder(vh, position);
        break;
    }
    case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: {
        throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager.");
    }
    }
}

From source file:ni.org.ics.estudios.appmovil.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);/*from w  ww .ja  va  2s .  co  m*/
    titleView.setTextColor(getResources().getColor(R.color.review_green));

    ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(mReviewAdapter);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    return rootView;
}

From source file:ru.arturvasilov.udacity.sunshinewatches.ItemChoiceManager.java

@SuppressWarnings("unchecked")
public void onClick(RecyclerView.ViewHolder vh) {
    if (mChoiceMode == AbsListView.CHOICE_MODE_NONE)
        return;//from  w ww . ja v  a 2 s.  c  o  m

    int checkedItemCount = mCheckStates.size();
    int position = vh.getAdapterPosition();

    if (position == RecyclerView.NO_POSITION) {
        Log.d(LOG_TAG, "Unable to Set Item State");
        return;
    }

    switch (mChoiceMode) {
    case AbsListView.CHOICE_MODE_NONE:
        break;
    case AbsListView.CHOICE_MODE_SINGLE: {
        boolean checked = mCheckStates.get(position, false);
        if (!checked) {
            for (int i = 0; i < checkedItemCount; i++) {
                mAdapter.notifyItemChanged(mCheckStates.keyAt(i));
            }
            mCheckStates.clear();
            mCheckStates.put(position, true);
            mCheckedIdStates.clear();
            mCheckedIdStates.put(mAdapter.getItemId(position), position);
        }
        // We directly call onBindViewHolder here because notifying that an item has
        // changed on an item that has the focus causes it to lose focus, which makes
        // keyboard navigation a bit annoying
        mAdapter.onBindViewHolder(vh, position);
        break;
    }
    case AbsListView.CHOICE_MODE_MULTIPLE: {
        boolean checked = mCheckStates.get(position, false);
        mCheckStates.put(position, !checked);
        // We directly call onBindViewHolder here because notifying that an item has
        // changed on an item that has the focus causes it to lose focus, which makes
        // keyboard navigation a bit annoying
        mAdapter.onBindViewHolder(vh, position);
        break;
    }
    case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: {
        throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager.");
    }
    }
}

From source file:com.sharpcart.android.wizardpager.wizard.ui.ReviewFragment.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);

    final TextView titleView = (TextView) rootView.findViewById(android.R.id.title);
    titleView.setText(R.string.review);/*from  w  w  w .  j ava  2  s .  c  om*/
    titleView.setTextColor(getResources().getColor(R.color.review_green));

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(mReviewAdapter);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    return rootView;
}

From source file:org.flexlabs.widgets.dualbattery.app.SettingsActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    fragments = new Fragment[4];
    fragments[0] = new SettingsFragment();
    fragments[1] = new FeedbackFragment();
    fragments[2] = new DonateFragment();
    fragments[3] = new AboutFragment();
    titles = new String[4];
    titles[0] = getString(R.string.settings);
    titles[1] = getString(R.string.propHeader_Feedback);
    titles[2] = getString(R.string.propHeader_Donate);
    titles[3] = getString(R.string.propHeader_About);

    int screenLayout = getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB
            && screenLayout > Configuration.SCREENLAYOUT_SIZE_LARGE) {
        setContentView(R.layout.preference_list_large);

        ArrayAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1,
                titles);/* w w w  .j a  v a 2 s  . c  o m*/

        mList = (ListView) findViewById(android.R.id.list);
        mList.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        mList.setOnItemClickListener(this);
        mList.setAdapter(adapter);
        mList.setItemChecked(0, true);
        mList.performClick();
        getSupportFragmentManager().beginTransaction().replace(R.id.prefs, fragments[0]).commit();
    } else {
        setContentView(R.layout.widgetsettings);
        PagerTabAdapter mPagerAdapter = new PagerTabAdapter(getSupportFragmentManager());
        ViewPager mPager = (ViewPager) findViewById(R.id.pager);
        mPager.setAdapter(mPagerAdapter);

        PageIndicator mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
        mIndicator.setViewPager(mPager);
    }
}

From source file:com.sharpcart.android.wizardpager.wizard.ui.SingleChoiceFragment.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_single_choice,
            android.R.id.text1, mChoices));
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

    // Pre-select currently selected item.
    new Handler().post(new Runnable() {
        @Override//from  w  w  w  .j  av a2s.co m
        public void run() {
            final 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:ni.org.ics.zikapositivas.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);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());
    ((TextView) rootView.findViewById(R.id.label_hint)).setText(mPage.getHint());

    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);

    // Pre-select currently selected item.
    new Handler().post(new Runnable() {
        @Override//from  ww  w  .j  a  v  a 2  s  .  co m
        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;
}