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:dev.ronlemire.receivers.ListViewFragment.java

public void refresh(int index) {
    mCurCheckPosition = index;/*from w w w.j ava  2  s . c  om*/

    // Populate list with our static array of titles.
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(parentActivity, R.array.list_titles,
            android.R.layout.simple_list_item_single_choice);
    setListAdapter(adapter);

    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    lv.setItemChecked(mCurCheckPosition, true);
    //lv.performItemClick(lv, mCurCheckPosition, lv.getItemIdAtPosition(mCurCheckPosition));      
}

From source file:bbct.android.common.provider.BaseballCardAdapter.java

@NonNull
@Override/*from w  ww .  j  a v a  2  s.  c  o m*/
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    BaseballCardView row = (BaseballCardView) convertView;

    if (row == null) {
        row = new BaseballCardView(mActivity);
    }

    CheckBox ctv = row.findViewById(R.id.checkmark);

    // set listener
    ctv.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked && !mCallback.isStarted()) {
                mActivity.startActionMode(mCallback);
            }

            ListView listView = mListFragment.getListView();
            // Add 1 to compensate for the header view
            listView.setItemChecked(position + 1, isChecked);
        }
    });

    BaseballCard card = getItem(position);
    row.setBaseballCard(card);

    return row;
}

From source file:br.com.PartoHumanizado.fragment.base.ResStringArrayListFragment.java

@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    if (savedInstanceState == null)
        return;/*from   www.j ava 2 s. c  o  m*/
    boolean[] booleans = savedInstanceState.getBooleanArray(getTitle());
    ListView listView = getListView();
    for (int i = 0; i < booleans.length; i++) {
        listView.setItemChecked(i, booleans[i]);
    }
}

From source file:br.com.PartoHumanizado.fragment.base.ResStringArrayListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    updateListView();//w ww  .  j a  va  2s. c o m
    getListView().setOnItemClickListener(this);

    FragmentActivity activity = getActivity();
    SharedPreferences preferences = getSharedPreferences(activity);
    ListView listView = getListView();

    for (int i = 0; i < listView.getCount(); i++)
        listView.setItemChecked(i, preferences.getBoolean(String.valueOf(i), false));
}

From source file:com.audiokernel.euphonyrmt.fragments.OutputsFragment.java

public void refreshOutputs() {
    mApp.oMPDAsyncHelper.execAsync(new Runnable() {
        @Override//from w w w .j a  v  a  2  s . c  om
        public void run() {
            try {
                final List<MPDOutput> mpdOutputs = mApp.oMPDAsyncHelper.oMPD.getOutputs();
                mOutputs.clear();
                mOutputs.addAll(mpdOutputs);
            } catch (final IOException | MPDException e) {
                Log.e(TAG, "Failed to list outputs.", e);
            }
            final Activity activity = getActivity();
            if (activity != null) {
                activity.runOnUiThread(new Runnable() {
                    @Override
                    @SuppressWarnings("unchecked")
                    public void run() {
                        try {
                            ((BaseAdapter) getListAdapter()).notifyDataSetChanged();
                            final ListView list = getListView();
                            for (int i = 0; i < mOutputs.size(); i++) {
                                list.setItemChecked(i, mOutputs.get(i).isEnabled());
                            }
                        } catch (IllegalStateException e) {
                            Log.e(TAG, "Illegal Activity state while trying to refresh output list");
                        }
                    }
                });
            }
        }
    });
}

From source file:de.stadtrallye.rallyesoft.fragments.AssistantGroupsFragment.java

private void restoreChoice(ListView list) {
    Integer pos = groupAdapter.findPosition(assistant.getGroup());

    if (pos != null) {
        list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        list.setItemChecked(pos, true);
    }//  w  w w.j  av a 2s  . c  o  m
}

From source file:de.micmun.android.deufeitage.FeiTagListActivity.java

/**
 * @see de.micmun.android.deufeitage.FeiTagListFragment.Callbacks#onItemSelected(String)
 *//* w  w  w. j  a v  a2 s  .c  om*/
@Override
public void onItemSelected(String id) {
    mId = id;

    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(FeiTagListActivity.KEY_ID, mId);
    editor.apply();

    if (mId == null)
        return;

    mYear = preferences.getInt(KEY_YEAR, -1);

    if (mTwoPane) {
        // In two-pane mode, show the detail view in this activity by
        // adding or replacing the detail fragment using a
        // fragment transaction.
        Bundle arguments = new Bundle();
        arguments.putString(FeiTagDetailFragment.ARG_ITEM_ID, mId);
        arguments.putInt(FeiTagDetailFragment.ARG_ITEM_YEAR, mYear);
        FeiTagDetailFragment fragment = new FeiTagDetailFragment();
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction().replace(R.id.feitag_detail_container, fragment).commit();

        StateItem currentItem = StateArrayAdapter.ITEM_MAP.get(mId);

        String title = getTitle().toString();
        String subtitle = currentItem.getName();
        setToolbarTitle(title, subtitle);

        ListView lv = ((FeiTagListFragment) getSupportFragmentManager().findFragmentById(R.id.feitag_list))
                .getListView();
        lv.setItemChecked(StateArrayAdapter.ITEMS.indexOf(currentItem), true);
    } else {
        // In single-pane mode, simply start the detail activity
        // for the selected item ID.
        Intent detailIntent = new Intent(this, FeiTagDetailActivity.class);
        detailIntent.putExtra(FeiTagDetailFragment.ARG_ITEM_ID, mId);
        detailIntent.putExtra(FeiTagDetailFragment.ARG_ITEM_YEAR, mYear);
        startActivity(detailIntent);
    }
}

From source file:com.jefftharris.passwdsafe.sync.SyncLogsFragment.java

@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
    if (l.isItemChecked(pos)) {
        if (pos == itsSelItemPos) {
            l.setItemChecked(pos, false);
            itsSelItemPos = -1;//from   w w w.  j  a v a 2  s  .c om
        } else {
            itsSelItemPos = pos;
        }
    }
    l.invalidateViews();
}

From source file:com.acrylicgoat.bcponline.fragments.CPListFragment.java

public void selectPosition() {
    ListView lv = getListView();
    if (dualFragments) {
        //Log.d("DDGListFragment","using dualFragments" );
        //Log.d("DDGListFragment","position = " + curPosition);

        lv.setItemChecked(curPosition, true);
    } else {//from   w w  w.j  a  va 2 s . c  o m
        lv.setItemChecked(curPosition, false);
    }

}

From source file:com.csipsimple.ui.filters.AccountFiltersListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    Log.d(THIS_FILE, "Checked " + position + " et " + id);

    ListView lv = getListView();
    lv.setItemChecked(position, true);

    curCheckFilterId = id;//  w  w  w.  j  a v  a  2  s .co m
    showDetails(id);
}