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:com.masteriti.manager.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*from  w w w .ja va2 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() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            @Override
            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() {
            @Override
            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.sakisds.icymonitor.activities.ConnectionActivity.java

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

    setContentView(R.layout.activity_connection);
    mSettings = getSharedPreferences(MainViewActivity.SHAREDPREFS_FILE, 0);

    refreshListAdapter();/*from   w ww  . java 2s  .  c  o m*/

    ListView listView = getListView();

    listView.setLongClickable(true);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new MultipleChoiceListener());

    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            String url = "http://" + ((TextView) v.findViewById(R.id.text_address)).getText().toString();
            connect(url);
        }
    });

    // Http Client
    mClient.setMaxRetriesAndTimeout(2, 2000);

    // Setup GCM
    context = getApplicationContext();
    regid = getRegistrationId(context);

    if (regid.length() == 0) {
        registerBackground();
    }
    gcm = GoogleCloudMessaging.getInstance(this);
}

From source file:com.bydavy.card.receipts.fragments.ReceiptListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final ListView listView = getListView();

    listView.setOnItemSelectedListener(this);
    listView.setOnItemLongClickListener(this);
    setListAdapter(mAdapter);/*from w ww  .  ja  v a2s . com*/

    if (mDualPane) {
        listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    }

    final Bundle bundle = mLoaderCallBack.createLoaderBundle(getCursorSelection(), getCursorSelectionArgs(),
            getCursorSortOrder());
    getLoaderManager().initLoader(CURSOR_LOADER_RECEIPT_LIST, bundle, mLoaderCallBack);
}

From source file:com.fututel.ui.chat.ChatListFragment.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  w w w. ja  va2 s.c  om*/
    } else {
        lv.setChoiceMode(ListView.CHOICE_MODE_NONE);
        lv.setItemsCanFocus(true);
    }

}

From source file:com.capstonecontrol.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from   w  w w  .  ja  v a2s .  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) {
                CapstoneControlActivity.userChanged = true;
                // 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();
                // clear the module list so that a new one will get found
                CapstoneControlActivity.modules.clear();
                // instead of finish() go back to the AccountsActivity for
                // new login.
                CapstoneControlActivity.googleUserName = (String) account.getText();
                Intent myIntent = new Intent(v.getContext(), SplashActivity.class);
                startActivity(myIntent);
                myIntent = new Intent(v.getContext(), CapstoneControlActivity.class);
                startActivity(myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            }
        });
    }
}

From source file:com.listomate.activities.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from www. j  a v a  2s.  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) {
                // Register in the background and terminate the activity
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                register((String) account.getText());
                finish();
            }
        });

        final Button exitButton = (Button) findViewById(R.id.exit);
        exitButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
    }
}

From source file:com.github.runoshun.in_app_survey.ui.QuestionFragment.java

protected View onCreateSingleChoiceView(final SingleChoiceQuestion question, LayoutInflater inflater,
        ViewGroup container, @SuppressWarnings("UnusedParameters") Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_default_choice, container, false);
    TextView questionView = (TextView) view.findViewById(R.id.survey_question);
    ListView listView = (ListView) view.findViewById(R.id.survey_listview);

    questionView.setText(question.question);

    ArrayAdapter<String> adapter = new ArrayAdapter<>(view.getContext(),
            android.R.layout.simple_list_item_single_choice, question.choices);
    listView.setAdapter(adapter);//from  w ww .ja v  a  2 s.  c  om
    listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            QuestionFragment.this.onSingleChoiceItemClick((ListView) adapterView, question);
        }
    });

    return view;
}

From source file:falcofinder.android.fuehrerschein.chat.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*  w  ww . j a  v a2s.  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);

        /* 
         * rimuovo aggiunta account perche' disponible da versione 2.2
         * ma voglio compatibilita' con 2.1
        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.github.runoshun.in_app_survey.ui.QuestionFragment.java

protected View onCreateMultiChoiceView(final MultiChoiceQuestion question, LayoutInflater inflater,
        ViewGroup container, @SuppressWarnings("UnusedParameters") Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_default_choice, container, false);
    TextView questionText = (TextView) view.findViewById(R.id.survey_question);
    ListView listView = (ListView) view.findViewById(R.id.survey_listview);

    questionText.setText(question.question);

    ArrayAdapter<String> adapter = new ArrayAdapter<>(view.getContext(),
            android.R.layout.simple_list_item_multiple_choice, question.choices);
    listView.setAdapter(adapter);//from w  w  w  .  j av a2 s  .  c o m
    listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            QuestionFragment.this.onMultiChoiceItemClick(question, (ListView) adapterView, position);
        }
    });

    return view;
}

From source file:com.Candy.sizer.CandySizer.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final ImageView delButton = (ImageView) getView().findViewById(R.id.btn_delete);
    final ImageView profileButton = (ImageView) getView().findViewById(R.id.btn_profile);

    if (delButton == null) {
        return;/*from  w  ww  . j ava2 s  .co m*/
    }

    // create arraylist of apps not to be removed
    final ArrayList<String> safetyList = new ArrayList<String>();
    safetyList.add("BackupRestoreConfirmation.apk");
    safetyList.add("CertInstaller.apk");
    safetyList.add("Contacts.apk");
    safetyList.add("ContactsProvider.apk");
    safetyList.add("DefaultContainerService.apk");
    safetyList.add("DownloadProvider.apk");
    safetyList.add("DrmProvider.apk");
    safetyList.add("MediaProvider.apk");
    safetyList.add("Mms.apk");
    safetyList.add("PackageInstaller.apk");
    safetyList.add("Phone.apk");
    safetyList.add("Settings.apk");
    safetyList.add("SettingsProvider.apk");
    safetyList.add("CandyOTA.apk");
    safetyList.add("Superuser.apk");
    safetyList.add("SystemUI.apk");
    safetyList.add("TelephonyProvider.apk");

    // create arraylist from /system/app content
    File system = new File(systemPath);
    String[] sysappArray = system.list();
    mSysApp = new ArrayList<String>(Arrays.asList(sysappArray));

    // remove "apps not to be removed" from list and sort list
    mSysApp.removeAll(safetyList);
    Collections.sort(mSysApp);

    // populate listview via arrayadapter
    adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_multiple_choice,
            mSysApp);

    final ListView lv = (ListView) getView().findViewById(R.string.listsystem);
    lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    lv.setAdapter(adapter);

    // longclick an entry
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
            // create deletion dialog
            String item = lv.getAdapter().getItem(arg2).toString();
            showDialog(DELETE_DIALOG, item, adapter, 0);
            return false;
        }
    });
    // click button delete
    delButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // check which items are selected
            String item = null;
            int itemCounter = 0;
            SparseBooleanArray checked = lv.getCheckedItemPositions();
            for (int i = lv.getCount() - 1; i > 0; i--) {
                if (checked.get(i)) {
                    item = mSysApp.get(i);
                    itemCounter++;
                }
            }
            if (item == null) {
                toast(getResources().getString(R.string.sizer_message_noselect));
                return;
            } else {
                showDialog(DELETE_MULTIPLE_DIALOG, item, adapter, itemCounter);
            }
        }
    });
    // click button profile
    profileButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // call select dialog
            selectDialog(mSysApp, adapter);
        }
    });
}