Example usage for android.widget ListView setItemChecked

List of usage examples for android.widget ListView setItemChecked

Introduction

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

Prototype

public void setItemChecked(int position, boolean value) 

Source Link

Document

Sets the checked state of the specified position.

Usage

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

    // Pre-select currently selected item.
    new Handler().post(new Runnable() {
        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;
                }/*  w  ww.jav  a 2  s  .  com*/
            }
        }
    });

    return rootView;
}

From source file:com.ultramegasoft.flavordex2.dialog.FileImportDialog.java

/**
 * Uncheck duplicate entries.//from   w w w  .j a v a2s . c  o m
 */
private void uncheckDuplicates() {
    if (mData == null) {
        return;
    }
    final ListView listView = getListView();
    for (int i = 0; i < mData.entries.size(); i++) {
        listView.setItemChecked(i, !mData.duplicates.contains(mData.entries.get(i)));
    }

    final int numDuplicates = mData.duplicates.size();
    if (numDuplicates > 0) {
        final String duplicates = getResources().getQuantityString(R.plurals.duplicates, numDuplicates);
        final String were = getResources().getQuantityString(R.plurals.were, numDuplicates);
        final String message = getString(R.string.message_duplicates_unchecked, numDuplicates, duplicates,
                were);
        Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show();
    }
}

From source file:br.com.hojeti.wizardpager.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());

    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//from  w w w  . j ava2s .  c o 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;
}

From source file:com.grottworkshop.gwswizardpager.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());

    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(new ArrayAdapter<>(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/*from  w w w .  j  av a 2s .  c  o 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;
}

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

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

From source file:mp.paschalis.ChooseLibraryFragment.java

/**
 * Get the selected Library//from  w ww. j  av a2s.  c  o m
 */
@Override
public void onListItemClick(ListView listView, View v, int position, long id) {

    // Save the library
    chosenLib = (Library) listView.getItemAtPosition(position);

    app.librarySelectedOnList = position;

    chosenLib.positionOnList = position;

    // Notify the parent activity of selected item
    mCallback.onLibrarySelected(chosenLib);

    // Set the item as checked to be highlighted when in two-pane layout
    listView.setItemChecked(position, true);

    listView.setSmoothScrollbarEnabled(true);
}

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// w  w  w.ja  va 2 s .c o  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;
}

From source file:com.silentcircle.contacts.editor.GroupMembershipView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void setGroupMetaData(Cursor groupMetaData) {
    this.mGroupMetaData = groupMetaData;
    updateView();/*w w  w  .j  av a  2 s  . co m*/
    // Open up the list of groups if a new group was just created.
    if (mCreatedNewGroup) {
        mCreatedNewGroup = false;
        onClick(this); // This causes the popup to open.
        if (mPopup != null || dialogPopup != null) {
            // Ensure that the newly created group is checked.
            int position = mAdapter.getCount() - 2;
            ListView listView = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) ? mPopup.getListView()
                    : GroupCheckPopup.modeList;
            if (!listView.isItemChecked(position)) {
                // Newly created group is not checked, so check it.
                listView.setItemChecked(position, true);
                onItemClick(listView, null, position, listView.getItemIdAtPosition(position));
            }
        }
    }
}

From source file:pl.arnea.footballadventuremanager.wizardpager.wizard.ui.SingleChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.wizardpager_single_page_fragment, 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(ListView.CHOICE_MODE_SINGLE);

    // Pre-select currently selected item.
    new Handler().post(new Runnable() {
        @Override//w ww  . jav a2  s . c  om
        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);
                    GlobalData.MYCLUBID = i;
                    break;
                }
            }
        }
    });

    return rootView;
}

From source file:com.ultramegasoft.flavordex2.dialog.FileImportDialog.java

@Override
public void onLoadFinished(@NonNull Loader<CSVUtils.CSVHolder> loader, CSVUtils.CSVHolder data) {
    final Context context = getContext();
    if (context != null && data != null) {
        setListShown(true);//from   www. j  av  a2s.c  o  m
        setListAdapter(new CSVListAdapter(context, data));

        final ListView listView = getListView();
        for (int i = 0; i < data.entries.size(); i++) {
            listView.setItemChecked(i, true);
        }

        mData = data;
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                validateData();
            }
        });
    } else {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                final FragmentManager fm = getFragmentManager();
                if (fm != null) {
                    MessageDialog.showDialog(fm, getString(R.string.title_error),
                            getString(R.string.error_csv_parse), R.drawable.ic_warning);
                }
                dismiss();
            }
        });
    }

    getLoaderManager().destroyLoader(0);
}