Example usage for android.widget ListView getCheckedItemPosition

List of usage examples for android.widget ListView getCheckedItemPosition

Introduction

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

Prototype

public int getCheckedItemPosition() 

Source Link

Document

Returns the currently checked item.

Usage

From source file:com.sigilance.CardEdit.MainActivity.java

private void promptForSexDo() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.lbl_sex);//  w ww .ja  v  a  2s  .co m

    String[] options = new String[] { getString(R.string.lbl_male), getString(R.string.lbl_female),
            getString(R.string.lbl_gender_unspecifed) };
    int currentIndex = -1;
    switch (mCardholderSex) {
    case "1":
        currentIndex = 0;
        break;
    case "2":
        currentIndex = 1;
        break;
    case "9":
        currentIndex = 2;
        break;
    }
    builder.setSingleChoiceItems(options, currentIndex, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
        }
    });

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ListView lw = ((AlertDialog) dialog).getListView();
            switch (lw.getCheckedItemPosition()) {
            case 0:
                mPendingOperations.add(new PendingPutDataOperation(DO_SEX, new byte[] { 0x31 }));
                break;
            case 1:
                mPendingOperations.add(new PendingPutDataOperation(DO_SEX, new byte[] { 0x32 }));
                break;
            case 2:
                mPendingOperations.add(new PendingPutDataOperation(DO_SEX, new byte[] { 0x39 }));
                break;
            default:
                return;
            }
            hideUi();
            findTextViewById(R.id.id_action_reqiured_warning).setText(R.string.warning_tap_card_to_save);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.create().show();
}

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

/**
 * Sets up the 'connect' screen content.
 *///from   ww w  . j  av  a2  s .  com
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.masteriti.manager.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 */// w  w w  . jav  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() {
            @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.sigilance.CardEdit.MainActivity.java

private void promptForPinBehaviorDo() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.lbl_signature_pin);

    String[] options = new String[] { getString(R.string.lbl_pin_forced),
            getString(R.string.lbl_pin_not_forced) };
    builder.setSingleChoiceItems(options, mPwStatusBytes[0], new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int index) {

        }/*from  w w w .  ja v a2  s.c o  m*/
    });

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ListView lw = ((AlertDialog) dialog).getListView();
            byte[] data;
            if (lw.getCheckedItemPosition() == 0)
                data = new byte[] { 0 };
            else
                data = new byte[] { 1 };
            mPendingOperations.add(new PendingPutDataOperation(DO_PW1_STATUS_BYTE, data));
            hideUi();
            findTextViewById(R.id.id_action_reqiured_warning).setText(R.string.warning_tap_card_to_save);
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    builder.create().show();
}

From source file:com.nest5.businessClient.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*ww  w  . ja  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) {
                // 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();
            }
        });
    }

    // internetConnectionStatus = (ImageView) findViewById(R.id.header_connection_status);
    SharedPreferences prefs = Util.getSharedPreferences(mContext);
    if (!isNetworkAvailable()) {
        internetConnectionStatus.setImageResource(R.drawable.error);

        prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_DISCONNECTED).commit();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(
                "No tienes una conexin a internet activa. Habiltala haciendo click en aceptar y seleccionando luego una red.")
                .setCancelable(false).setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
                        startActivityForResult(intent, 1);
                    }
                }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();

    } else {
        prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_CONNECTED).commit();
    }
}

From source file:com.nachiket.titan.LibraryActivity.java

@Override
public void onDismiss(DialogInterface dialog) {
    ListView list = ((AlertDialog) dialog).getListView();
    // subtract 1 for header
    int which = list.getCheckedItemPosition() - 1;

    RadioGroup group = (RadioGroup) list.findViewById(R.id.sort_direction);
    if (group.getCheckedRadioButtonId() == R.id.descending)
        which = ~which;//from w  ww. ja  va 2 s . com

    mPagerAdapter.setSortMode(which);
}

From source file:com.capstonecontrol.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from w  ww.  ja va  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) {
                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.waz.zclient.pages.main.pickuser.PickUserFragment.java

@Override
public void onContactListContactClicked(final ContactDetails contactDetails) {
    getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new DefaultNetworkAction() {
        @Override/*  www  .  j  a  v a 2 s  .co m*/
        public void execute(NetworkMode networkMode) {
            final int contactMethodsCount = contactDetails.getContactMethods().size();
            final ContactMethod[] contactMethods = contactDetails.getContactMethods()
                    .toArray(new ContactMethod[contactMethodsCount]);

            if (contactMethodsCount == 1 && contactMethods[0].getKind() == ContactMethod.Kind.SMS) {
                // Launch SMS app directly if contact only has phone numner
                final String number = contactMethods[0].getStringRepresentation();
                sendSMSInvite(number);
                ((BaseActivity) getActivity()).injectJava(GlobalTrackingController.class)
                        .tagEvent(new OpenedGenericInviteMenuEvent(
                                OpenedGenericInviteMenuEvent.EventContext.ADDRESSBOOK));
                return;
            }

            final CharSequence[] itemNames = new CharSequence[contactMethodsCount];
            for (int i = 0; i < contactMethodsCount; i++) {
                ContactMethod contactMethod = contactMethods[i];
                itemNames[i] = contactMethod.getStringRepresentation();
            }

            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

            builder.setTitle(
                    getResources().getString(R.string.people_picker__contact_list__invite_dialog__title))
                    .setPositiveButton(getResources().getText(R.string.confirmation_menu__confirm_done),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    ListView lv = dialog.getListView();
                                    int selected = lv.getCheckedItemPosition();
                                    ContactMethod selectedContactMethod = null;
                                    if (selected >= 0) {
                                        selectedContactMethod = contactMethods[selected];
                                    }
                                    if (selectedContactMethod == null) {
                                        return;
                                    }

                                    if (selectedContactMethod.getKind() == ContactMethod.Kind.SMS) {
                                        final String number = String.valueOf(itemNames[selected]);
                                        sendSMSInvite(number);
                                        ((BaseActivity) getActivity())
                                                .injectJava(GlobalTrackingController.class)
                                                .tagEvent(new OpenedGenericInviteMenuEvent(
                                                        OpenedGenericInviteMenuEvent.EventContext.ADDRESSBOOK));
                                    } else {
                                        selectedContactMethod.invite(" ", null);
                                        Toast.makeText(getActivity(),
                                                getResources().getString(
                                                        R.string.people_picker__invite__sent_feedback),
                                                Toast.LENGTH_LONG).show();
                                        boolean fromSearch = TextUtils.isEmpty(getControllerFactory()
                                                .getPickUserController().getSearchFilter());
                                        TrackingUtils.tagSentInviteToContactEvent(
                                                ((BaseActivity) getActivity())
                                                        .injectJava(GlobalTrackingController.class),
                                                selectedContactMethod.getKind(),
                                                contactDetails.hasBeenInvited(), fromSearch);
                                    }
                                }
                            })
                    .setNegativeButton(getResources().getText(R.string.confirmation_menu__cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    dialogInterface.cancel();
                                }
                            })
                    .setSingleChoiceItems(itemNames, DEFAULT_SELECTED_INVITE_METHOD, null);

            dialog = builder.create();
            dialog.show();

            ((BaseActivity) getActivity()).injectJava(GlobalTrackingController.class)
                    .onApplicationScreen(ApplicationScreen.SEND_PERSONAL_INVITE_MENU);
        }
    });
}

From source file:mp.teardrop.LibraryActivity.java

@Override
public void onDismiss(DialogInterface dialog) {
    ListView list = ((AlertDialog) dialog).getListView();
    // subtract 1 for header
    int which = list.getCheckedItemPosition() - 1;

    RadioGroup group = (RadioGroup) list.findViewById(R.id.sort_direction);
    if (group.getCheckedRadioButtonId() == R.id.descending) {
        which = ~which;/*ww  w  .j a va 2s .  c o m*/
    }

    mPagerAdapter.setSortMode(which);
}

From source file:no.nordicsemi.android.nrftoolbox.dfu.DfuActivity.java

/**
 * Called when Select File was pressed/* w w w. j av  a2  s  .c  o  m*/
 * 
 * @param view
 *            a button that was pressed
 */
public void onSelectFileClicked(final View view) {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("application/octet-stream");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // file browser has been found on the device
        startActivityForResult(intent, SELECT_FILE_REQ);
    } else {
        // there is no any file browser app, let's try to download one
        final View customView = getLayoutInflater().inflate(R.layout.app_file_browser, null);
        final ListView appsList = (ListView) customView.findViewById(android.R.id.list);
        appsList.setAdapter(new FileBrowserAppsAdapter(this));
        appsList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        appsList.setItemChecked(0, true);
        new AlertDialog.Builder(this).setTitle(R.string.dfu_alert_no_filebrowser_title).setView(customView)
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        dialog.dismiss();
                    }
                }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        final int pos = appsList.getCheckedItemPosition();
                        if (pos >= 0) {
                            final String query = getResources()
                                    .getStringArray(R.array.dfu_app_file_browser_action)[pos];
                            final Intent storeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(query));
                            startActivity(storeIntent);
                        }
                    }
                }).show();
    }
}