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:name.gumartinm.weather.information.fragment.overview.OverviewFragment.java

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

    final ListView listWeatherView = this.getListView();
    listWeatherView.setChoiceMode(ListView.CHOICE_MODE_NONE);

    if (savedInstanceState != null) {
        // Restore UI state
        final Forecast forecast = (Forecast) savedInstanceState.getSerializable("Forecast");

        if (forecast != null) {
            final PermanentStorage store = new PermanentStorage(this.getActivity().getApplicationContext());
            store.saveForecast(forecast);
        }//from   ww  w  .  ja  va 2s .  c o m
    }

    this.setHasOptionsMenu(false);

    this.setEmptyText(this.getString(R.string.text_field_remote_error));
    this.setListShownNoAnimation(false);
}

From source file:com.brookmanholmes.bma.wizard.ui.BaseChoiceFragment.java

protected void setListView(View view) {
    final ListView listView = (ListView) view.findViewById(android.R.id.list);
    listView.setTag(page.getClass().getSimpleName()); // used for espresso testing
    Log.i("BaseChoiceFragment", (String) listView.getTag());
    setAdapter();/*from  w w  w  .j  a  v  a  2 s.  com*/
    listView.setDividerHeight(0);
    listView.setChoiceMode(choiceMode);
}

From source file:com.abcvoipsip.ui.calllog.CallLogListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // View management
    mDualPane = getResources().getBoolean(R.bool.use_dual_panes);

    // Modify list view
    ListView lv = getListView();
    lv.setVerticalFadingEdgeEnabled(true);
    // lv.setCacheColorHint(android.R.color.transparent);
    if (mDualPane) {
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        lv.setItemsCanFocus(false);//from   ww  w .  j  a va2s  .co  m
    } else {
        lv.setChoiceMode(ListView.CHOICE_MODE_NONE);
        lv.setItemsCanFocus(true);
    }

    // Start out with a progress indicator.
    // setListShown(false);
}

From source file:com.csipsimple.ui.calllog.CallLogListFragment.java

private void turnOnActionMode() {
    Log.d(THIS_FILE, "Long press");
    mMode = getSherlockActivity().startActionMode(new CallLogActionMode());
    ListView lv = getListView();
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

}

From source file:com.example.flashcards.wizardpager.wizard.ui.TopicChoiceFragment.java

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

    Log.d(LOG_TAG, "TopicFragment onCreateView");
    View rootView = inflater.inflate(R.layout.fragment_page, container, false);
    Log.d(LOG_TAG, "TopicFragment infalted");
    ((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  ww . 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:com.wizard.ui.BS11ReviewFragment.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("Review");
    titleView.setTextColor(Color.parseColor("#33ff33"));

    ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    setListAdapter(mReviewAdapter);/*www .  j  a v  a 2 s.co  m*/
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    return rootView;
}

From source file:it.geosolutions.android.map.fragment.sources.SourcesFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    //set the listener for add button
    ImageButton add = (ImageButton) view.findViewById(R.id.sources_add);
    add.setOnClickListener(new OnClickListener() {

        @Override/*from   w ww.j  a  va2 s .c om*/
        public void onClick(View v) {
            Intent i = new Intent(getActivity(), NewSourceActivity.class);
            getActivity().startActivityForResult(i, Constants.requestCodes.CREATE_SOURCE);

        }
    });

    //
    //Set Contextual ACTION BAR CALLBACKS
    //
    final SourcesFragment callback = this;
    ListView lv = getListView();
    lv.setLongClickable(true);
    lv.setClickable(true);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    //edit - delete
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            LayerStore sel = adapter.getItem(position);

            if (!selected.contains(sel)) {
                getListView().setItemChecked(position, true);
                selected.add(sel);

            } else {
                getListView().setItemChecked(position, false);
                selected.remove(sel);
            }
            int numSelected = selected.size();
            if (numSelected > 0) {
                if (actionMode != null) {
                    updateCAB(numSelected);
                } else {
                    actionMode = getSherlockActivity().startActionMode(callback);
                    //override the done button to deselect all when the button is pressed
                    int doneButtonId = Resources.getSystem().getIdentifier("action_mode_close_button", "id",
                            "android");
                    View doneButton = getActivity().findViewById(doneButtonId);
                    doneButton.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            getListView().clearChoices();
                            selected = new ArrayList<LayerStore>();
                            actionMode.finish();
                        }
                    });
                }
            } else {
                if (actionMode != null) {
                    actionMode.finish();
                }
            }
            view.setSelected(true);
            return true;
        }
    });
    //browse
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LayerStore s = (LayerStore) adapter.getItem(position);
            s.openDetails(getSherlockActivity());
        }
    });

    super.onViewCreated(view, savedInstanceState);
}

From source file:com.cloudtask1.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from w  w  w .  j  a v a  2  s.co m
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:nz.ac.wintec.soit.af5.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*from   w  ww .j  av  a2 s .c  o  m*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //  startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:com.abcvoipsip.ui.messages.ConversationsListFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // View management
    mDualPane = getResources().getBoolean(R.bool.use_dual_panes);

    // Modify list view
    ListView lv = getListView();
    lv.setVerticalFadingEdgeEnabled(true);
    // lv.setCacheColorHint(android.R.color.transparent);
    if (mDualPane) {
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        lv.setItemsCanFocus(false);/* w w w  . j a va  2  s  . c o  m*/
    } else {
        lv.setChoiceMode(ListView.CHOICE_MODE_NONE);
        lv.setItemsCanFocus(true);
    }
}