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:org.flexlabs.widgets.dualbattery.widgetsettings.WidgetActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startService(new Intent(this, MonitorService.class));
    Bundle extras = getIntent().getExtras();
    appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);

    fragments = new Fragment[5];
    fragments[0] = new BatteryInfoFragment();
    fragments[1] = new PropertiesFragment();
    fragments[2] = new FeedbackFragment();
    fragments[3] = new DonateFragment();
    fragments[4] = new AboutFragment();
    titles = new String[5];
    titles[0] = getString(R.string.propHeader_BatteryInfo);
    titles[1] = getString(R.string.propHeader_Properties);
    titles[2] = getString(R.string.propHeader_Feedback);
    titles[3] = getString(R.string.propHeader_Donate);
    titles[4] = 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  a2 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);
    }

    if (WidgetSettingsContainer.getUpgradeSwappedSingle(this, appWidgetId)) {
        new AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(R.string.alert_just_swapped)
                .setPositiveButton("OK", null).show();
    }
}

From source file:com.harlie.android.sunshine.app.ItemChoiceManager.java

@SuppressWarnings("unchecked")
public void onClick(RecyclerView.ViewHolder vh) {
    if (mChoiceMode == AbsListView.CHOICE_MODE_NONE)
        return;/*from  w w w.j av  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); // warning: Unchecked call to 'onBindViewHolder(VH, int)' as a member of raw type 'android.support.v7.widget.RecyclerView.Adapter'
        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); // warning: Unchecked call to 'onBindViewHolder(VH, int)' as a member of raw type 'android.support.v7.widget.RecyclerView.Adapter'
        break;
    }
    case AbsListView.CHOICE_MODE_MULTIPLE_MODAL: {
        throw new RuntimeException("Multiple Modal not implemented in ItemChoiceManager.");
    }
    }
}

From source file:org.pixmob.droidlink.ui.EventsFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    prefs = getActivity().getSharedPreferences(SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);

    cursorAdapter = new EventCursorAdapter(getActivity());
    setListAdapter(cursorAdapter);//w  w  w.j  a v a 2s.  c  o m
    setHasOptionsMenu(true);

    // One event selected at a time.
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

    // The list is hidden until event cursor is loaded.
    setListShown(false);
    setEmptyText(getString(R.string.no_events));

    // Start event loading.
    getLoaderManager().initLoader(0, null, this);
}

From source file:nz.ac.otago.psyanlab.common.PaleListFragment.java

public void setActivateOnItemClick(boolean activateOnItemClick) {
    getListView()//from   w ww  .  j  av  a 2s.  c  o  m
            .setChoiceMode(activateOnItemClick ? AbsListView.CHOICE_MODE_SINGLE : AbsListView.CHOICE_MODE_NONE);
    mActivateOnItemClick = activateOnItemClick;
}

From source file:org.pixmob.feedme.ui.EntriesFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    prefs = getActivity().getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
    prefsEditor = prefs.edit();/*from  ww w.ja  va  2 s . c o m*/

    refreshEntriesIntent = new Intent(getActivity(), EntriesDownloadService.class);

    cursorAdapter = new EntryCursorAdapter(getActivity());
    setListAdapter(cursorAdapter);

    // One selected event at a time.
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

    // The list is hidden until event cursor is loaded.
    setListShown(false);
    setEmptyText(getString(R.string.no_entry_found));

    // Start entries loading.
    getLoaderManager().initLoader(0, null, this);

    if (savedInstanceState != null) {
        final String selectedEntryUriStr = savedInstanceState.getString("selectedEntryUri");
        selectedEntryUri = selectedEntryUriStr == null ? null : Uri.parse(selectedEntryUriStr);

        final EntryDetailsFragment edf = (EntryDetailsFragment) getSupportFragmentManager()
                .findFragmentById(R.id.entry_details);
        if (edf != null) {
            final OnEntrySelectionListener listener = listenerRef != null ? listenerRef.get() : null;
            if (listener != null) {
                try {
                    listener.onEntrySelected(selectedEntryUri);
                } catch (Exception e) {
                    Log.e(TAG, "Failed to select entry: " + selectedEntryUri, e);
                }
            }
        }
    }
}

From source file:com.google.devrel.samples.memedroid.app.CreateActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.translate_in_top, R.anim.translate_out_top);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_create);
    if (getActionBar() != null) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from   ww  w.  j av a  2  s  .c o m*/
    mHandler = new Handler();

    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
    GridView gridView = (GridView) findViewById(R.id.template_grid);
    if (viewPager != null) {
        PagerAdapter adapter = new MemeTemplatePagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(adapter);
        mAdapter = (TemplateAdapter) adapter;
        viewPager.setOffscreenPageLimit(3);
        viewPager.setPageMargin(-54);
        viewPager.setOnPageChangeListener(this);
        mCurrentView = viewPager;
        findViewById(R.id.meme_template_number).setVisibility(View.VISIBLE);
    } else if (gridView != null) {
        ListAdapter adapter = new MemeTemplateAdapter(this, R.layout.fragment_meme);
        gridView.setAdapter(adapter);
        mAdapter = (TemplateAdapter) adapter;
        mCurrentView = gridView;
        gridView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        gridView.setOnItemClickListener(this);
    } else {
        throw new IllegalStateException("No valid layout found.");
    }
    getSupportLoaderManager().initLoader(MEME_TEMPLATE_LIST, null, this);
    if (savedInstanceState != null) {
        mHasText = savedInstanceState.getBoolean(STATE_TEXT, false);
        getSupportLoaderManager().restartLoader(MEME_TEMPLATE_LIST, null, CreateActivity.this);
    }
    EditText et = (EditText) findViewById(R.id.top_text);
    et.addTextChangedListener(this);
    setProgressBarIndeterminateVisibility(true);
}

From source file:com.pileproject.drive.setting.machine.BluetoothMachineSelectFragment.java

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

    resizeDialog();//  w  ww.ja va 2 s. c o m

    mPairedDevicesListView.setAdapter(new BluetoothMachineListAdapter(getActivity(),
            R.layout.view_bluetooth_machine_list, new LinkedList<BluetoothDevice>()));
    mPairedDevicesListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    mPairedDevicesListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            BluetoothDevice bluetoothDevice = (BluetoothDevice) listView.getItemAtPosition(position);

            MachinePreferences.get(getActivity()).setMacAddress(bluetoothDevice.getAddress());

            Toast.makeText(getActivity(), getString(R.string.setting_bluetoothMachineSelect_toast_setDefault)
                    + "\n" + bluetoothDevice.getName(), Toast.LENGTH_LONG).show();
        }
    });

    mNewDevicesListView.setAdapter(new BluetoothMachineListAdapter(getActivity(),
            R.layout.view_bluetooth_machine_list, new LinkedList<BluetoothDevice>()));
    mNewDevicesListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            BluetoothDevice bluetoothDevice = (BluetoothDevice) listView.getItemAtPosition(position);

            final String bluetoothDeviceName = bluetoothDevice.getName();

            ProgressDialogFragment.showDialog(getActivity(), getChildFragmentManager(),
                    R.string.setting_bluetoothMachineSelect_progress_connecting_title,
                    R.string.setting_bluetoothMachineSelect_progress_connecting_message, "tag");

            // cancel scanning process because this is very heavyweight
            BluetoothAdapter.getDefaultAdapter().cancelDiscovery();

            mSubscriptions.add(RxBluetoothConnector.pairing(bluetoothDevice)
                    .observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<BluetoothDevice>() {
                        @Override
                        public void onCompleted() {
                            updatePairedList();

                            BluetoothAdapter.getDefaultAdapter().startDiscovery();

                            ProgressDialogFragment.dismissDialog();
                        }

                        @Override
                        public void onError(Throwable e) {
                            BluetoothAdapter.getDefaultAdapter().startDiscovery();

                            Toast.makeText(getActivity(),
                                    getString(R.string.setting_bluetoothMachineSelect_toast_cannotConnect,
                                            bluetoothDeviceName),
                                    Toast.LENGTH_LONG).show();

                            ProgressDialogFragment.dismissDialog();
                        }

                        @Override
                        public void onNext(BluetoothDevice bluetoothDevice) {
                            MachinePreferences.get(getActivity()).setMacAddress(bluetoothDevice.getAddress());

                            Toast.makeText(getActivity(),
                                    getString(R.string.setting_bluetoothMachineSelect_toast_setDefault,
                                            bluetoothDeviceName),
                                    Toast.LENGTH_LONG).show();

                            BluetoothMachineListAdapter adapter = (BluetoothMachineListAdapter) mNewDevicesListView
                                    .getAdapter();
                            adapter.remove(bluetoothDevice);
                        }
                    }));
        }
    });
}

From source file:com.nextgis.rehacompdemo.RoutingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_routing);

    String sRadius = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.PREF_RADIUS, "6");
    mActivationDistance = Integer.parseInt(sRadius);

    int routeNum = -1;
    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        routeNum = extras.getInt(Constants.BUNDLE_ROUTE_ID);

        if (getSupportActionBar() != null)
            getSupportActionBar().setTitle(extras.getString(Constants.BUNDLE_ROUTE_NAME));
    }/*  w  w  w  .  j  a  v  a2  s .co m*/

    if (routeNum == -1)
        return;

    mRoute = "route_" + routeNum;
    mPoints = "points_" + routeNum;

    mSteps = (ListView) findViewById(R.id.lv_steps);
    mAdapter = new StepAdapter(this, R.layout.item_step, getRouteSteps());
    mSteps.setAdapter(mAdapter);
    mSteps.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

    mSteps.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //                view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
            mSteps.requestFocusFromTouch();
            mSteps.setSelection(position);
        }
    });

    mMap = (MapDrawable) ((GISApplication) getApplication()).getMap();
    new MapLoader().execute();

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, Constants.GPS_MIN_TIME,
            Constants.GPS_MIN_DIST, this);
}

From source file:com.hangulo.powercontact.ErrorContactsListFragment.java

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

    // Set up ListView, assign adapter and set some listeners. The adapter was previously
    // created in onCreate().
    setListAdapter(mAdapter);//from w  w  w.  j a va 2s  .c  o  m
    getListView().setOnItemClickListener(this);
    getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);

    if (savedInstanceState != null) {

        mLastDataId = savedInstanceState.getLong(LAST_DATA_ID_KEY, -1);
        mLastContactId = savedInstanceState.getLong(LAST_CONTACT_ID_KEY, -1);
        mLastLookupKey = savedInstanceState.getString(LAST_LOOKUP_KEY, "");
    }

}

From source file:com.jbirdvegas.mgerrit.PatchSetViewerFragment.java

private void init() {
    View currentFragment = this.getView();

    ExpandableListView mListView = (ExpandableListView) currentFragment.findViewById(R.id.commit_cards);
    disconnectedView = currentFragment.findViewById(R.id.disconnected_view);

    sIsLegacyVersion = !Config.isDiffSupported(mParent);

    mAdapter = new CommitDetailsAdapter(mParent);
    mListView.setAdapter(mAdapter);//from  ww  w  . ja  v  a  2s . c o  m

    // Child click listeners (relevant for the changes cards)
    mListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    mFilesCAB = new FilesCAB(mParent, !sIsLegacyVersion);
    mAdapter.setContextualActionBar(mFilesCAB);
    mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            ExpandableListView listView = (ExpandableListView) parent;
            long pos = listView.getExpandableListPosition(position);
            int groupPos = ExpandableListView.getPackedPositionGroup(pos);
            int childPos = ExpandableListView.getPackedPositionChild(pos);

            if (!mAdapter.isLongClickSupported(groupPos, childPos)) {
                return false;
            }

            // In case this is a group view and does not have the change number tagged
            view.setTag(R.id.changeID, mSelectedChange);
            FilesCAB.TagHolder holder = new FilesCAB.TagHolder(view, mContext, groupPos, childPos >= 0);

            // Set the title to be shown in the action bar
            if (holder.filePath != null) {
                mFilesCAB.setTitle(holder.filePath);
            } else {
                String s = mParent.getResources().getString(R.string.change_detail_heading);
                mFilesCAB.setTitle(String.format(s, holder.changeNumber.intValue()));
            }

            mFilesCAB.setActionMode(getActivity().startActionMode(mFilesCAB));
            ActionMode actionMode = mFilesCAB.getActionMode();

            // Call requires API 14 (ICS)
            actionMode.setTag(holder);
            view.setSelected(true);
            return true;
        }
    });
    mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {
            // This is only valid for the changed files group
            int childItemType = mAdapter.getChildType(groupPosition, childPosition);
            if (childItemType != CommitDetailsAdapter.Cards.CHANGED_FILES.ordinal()) {
                return false;
            }
            // View the diff and close the CAB if a change diff could be viewed
            boolean diffLaunched = PatchSetChangesCard.onViewClicked(mParent, v);
            if (diffLaunched) {
                ActionMode mode = mFilesCAB.getActionMode();
                if (mode != null)
                    mode.finish();
            }
            return diffLaunched;
        }
    });

    mUrl = new GerritURL();

    Button retryButton = (Button) currentFragment.findViewById(R.id.btn_retry);
    retryButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (sIsLegacyVersion)
                sendRequest(GerritService.DataType.Commit);
            else
                sendRequest(GerritService.DataType.LegacyCommitDetails);
        }
    });

    if (getArguments() == null) {
        /** This should be the default value of {@link ChangeListFragment.mSelectedStatus } */
        setStatus(JSONCommit.Status.NEW.toString());
        loadChange(true);
    } else {
        Bundle args = getArguments();
        setStatus(args.getString(STATUS));
        String changeid = args.getString(CHANGE_ID);
        mChangeNumber = args.getInt(CHANGE_NO);

        if (changeid != null && !changeid.isEmpty()) {
            loadChange(changeid);
        }
    }

    mEventBus = EventBus.getDefault();
}