List of usage examples for android.widget ArrayAdapter getItem
@Override public @Nullable T getItem(int position)
From source file:com.eugene.fithealthmaingit.MainActivity.java
private void widgetAdd() { AlertDialog.Builder builderSingle = new AlertDialog.Builder(MainActivity.this).setTitle("Choose Meal: "); final ArrayAdapter<String> mAdapterMoveMeal = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1); mAdapterMoveMeal.add("Snack"); mAdapterMoveMeal.add("Breakfast"); mAdapterMoveMeal.add("Lunch"); mAdapterMoveMeal.add("Dinner"); builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override/* w w w . j a v a 2 s . c o m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(mAdapterMoveMeal, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = mAdapterMoveMeal.getItem(which); Intent i = new Intent(MainActivity.this, ChooseAddMealActivity.class); i.putExtra(Globals.MEAL_TYPE, strName); startActivity(i); } }); builderSingle.show(); }
From source file:info.guardianproject.otr.app.im.app.AccountWizardActivity.java
private void addGoogleAccount() { // mNewUser = newUser; AlertDialog.Builder builderSingle = new AlertDialog.Builder(this); // builderSingle.setTitle("Select One Name:-"); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice); for (Account gAccount : mGoogleAccounts) arrayAdapter.add(gAccount.name); builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override//from w w w . j ava 2 s . c om public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mNewUser = arrayAdapter.getItem(which); Thread thread = new Thread() { @Override public void run() { //get the oauth token //don't store anything just make sure it works! String password = GTalkOAuth2.NAME + ':' + GTalkOAuth2.getGoogleAuthTokenAllow(mNewUser, getApplicationContext(), AccountWizardActivity.this, mHandlerGoogleAuth); //use the XMPP type plugin for google accounts, and the .NAME "X-GOOGLE-TOKEN" as the password showSetupAccountForm(helper.getProviderNames().get(0), mNewUser, password, false, getString(R.string.google_account), false); } }; thread.start(); } }); builderSingle.show(); }
From source file:com.doplgangr.secrecy.settings.SettingsFragment.java
void choosePath(final getFileListener listener) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(context); builderSingle.setTitle(context.getString(R.string.Settings__select_storage_title)); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context, R.layout.select_dialog_singlechoice); final Map<String, File> storages = Util.getAllStorageLocations(); for (String key : storages.keySet()) { arrayAdapter.add(key);//from ww w.j a v a 2 s .com } builderSingle.setNegativeButton(R.string.CANCEL, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); File file = storages.get(strName); listener.get(file); } }); builderSingle.show(); }
From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java
private void InitiateClick() { listContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//w w w .j a v a2s. co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mealId1 = mItem.get(position - 1).getID(); mealBrand = mItem.get(position - 1).getBrand(); mealFaborite = "false"; AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()) .setTitle("Choose Meal: "); final ArrayAdapter<String> mAdapterMoveMeal = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1); mAdapterMoveMeal.add("Snack"); mAdapterMoveMeal.add("Breakfast"); mAdapterMoveMeal.add("Lunch"); mAdapterMoveMeal.add("Dinner"); builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(mAdapterMoveMeal, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = mAdapterMoveMeal.getItem(which); Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class); i.putExtra(Globals.MEAL_TYPE, strName); i.putExtra(Globals.MEAL_FAVORITE, "false"); i.putExtra(Globals.MEAL_ID, mealId1); i.putExtra(Globals.MEAL_BRAND, mealBrand); startActivity(i); } }); builderSingle.show(); } }); }
From source file:de.mprengemann.hwr.timetabel.TimetableActivity.java
private void initListNavigation() { Context context = getSupportActionBar().getThemedContext(); final ArrayAdapter<CharSequence> listAdapter = new ArrayAdapter<CharSequence>(context, R.layout.sherlock_spinner_item, application.getEventsDates()); listAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); if (listAdapter.isEmpty()) { getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); } else {//from w w w.j av a 2 s . c o m getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); } getSupportActionBar().setListNavigationCallbacks(listAdapter, new OnNavigationListener() { @Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { subjectFragment.scrollTo(String.valueOf(listAdapter.getItem(itemPosition))); return true; } }); }
From source file:org.eyeseetea.malariacare.LoginActivity.java
private void initDataDownloadPeriodDropdown() { if (!BuildConfig.loginDataDownloadPeriod) { return;// w ww .j a v a2s .c o m } ViewGroup loginViewsContainer = (ViewGroup) findViewById(R.id.login_dynamic_views_container); getLayoutInflater().inflate(R.layout.login_spinner, loginViewsContainer, true); //Add left text for the spinner "title" findViewById(R.id.date_spinner_container).setVisibility(View.VISIBLE); TextView textView = (TextView) findViewById(R.id.data_text_view); textView.setText(R.string.download); //add options ArrayList<String> dataLimitOptions = new ArrayList<>(); dataLimitOptions.add(getString(R.string.no_data)); dataLimitOptions.add(getString(R.string.last_6_days)); dataLimitOptions.add(getString(R.string.last_6_weeks)); dataLimitOptions.add(getString(R.string.last_6_months)); final ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, dataLimitOptions); spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //add spinner Spinner spinner = (Spinner) findViewById(R.id.data_spinner); spinner.setVisibility(View.VISIBLE); spinner.setAdapter(spinnerArrayAdapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { PreferencesState.getInstance().setDataLimitedByDate(spinnerArrayAdapter.getItem(pos).toString()); } public void onNothingSelected(AdapterView<?> parent) { } }); //select the selected option or default no data option String dateLimit = PreferencesState.getInstance().getDataLimitedByDate(); if (dateLimit.equals("")) { spinner.setSelection(spinnerArrayAdapter.getPosition(getString(R.string.no_data))); } else { spinner.setSelection(spinnerArrayAdapter.getPosition(dateLimit)); } }
From source file:com.metinkale.prayerapp.BaseActivity.java
@Override public void setContentView(int res) { super.setContentView(R.layout.activity_base); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); if (toolbar != null) { setSupportActionBar(toolbar);/*from w w w . j av a2s. c o m*/ toolbar.setBackgroundResource(R.color.colorPrimary); toolbar.setNavigationIcon( MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.VIEW_HEADLINE) .setColor(Color.WHITE).setToActionbarSize().build()); } ViewGroup content = (ViewGroup) findViewById(R.id.basecontent); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer); View v = LayoutInflater.from(this).inflate(res, content, false); content.addView(v, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mNav = (ListView) mDrawerLayout.findViewById(R.id.base_nav); ArrayAdapter<String> list = new ArrayAdapter<String>(this, R.layout.drawer_list_item, getResources().getStringArray(R.array.dropdown)) { @NonNull @Override public View getView(int pos, View v, @NonNull ViewGroup p) { v = super.getView(pos, v, p); if (pos == mNavPos) { ((TextView) v).setTypeface(null, Typeface.BOLD); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && getResources().getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { ((TextView) v).setCompoundDrawablesWithIntrinsicBounds(0, 0, ICONS[pos], 0); } else { ((TextView) v).setCompoundDrawablesWithIntrinsicBounds(ICONS[pos], 0, 0, 0); } return v; } }; mNav.setAdapter(list); mNav.setOnItemClickListener(new MyClickListener()); final String title = list.getItem(mNavPos); mDrawerLayout.post(new Runnable() { @Override public void run() { if (toolbar != null) { toolbar.setTitle(title); } } }); if (getIntent().getBooleanExtra("anim", false)) { mDrawerLayout.openDrawer(GravityCompat.START); mDrawerLayout.post(new Runnable() { @Override public void run() { mDrawerLayout.closeDrawers(); } }); } }
From source file:com.songcode.materialnotes.ui.NotesListActivity.java
private void updateDrawerWithState(ListEditState state) { if (mNavigationListView == null) { Log.e(TAG, "mNavigationListView == null"); return;/*from w ww.ja v a2s.c om*/ } String[] itemsStrings = null; final String createNewStr = getString(R.string.notelist_menu_new); final String createFolderStr = getString(R.string.menu_create_folder); final String exportTextStr = getString(R.string.menu_export_text); final String syncStr = getString(R.string.menu_sync); final String cancelSyncStr = getString(R.string.menu_sync_cancel); final String syncStateStr = GTaskSyncService.isSyncing() ? cancelSyncStr : syncStr; final String searchStr = getString(R.string.menu_search); final String setStr = getString(R.string.menu_setting); if (state == ListEditState.NOTE_LIST) { itemsStrings = new String[] { createNewStr, createFolderStr, exportTextStr, syncStateStr, searchStr, setStr }; } else if (state == ListEditState.SUB_FOLDER) { itemsStrings = new String[] { createNewStr }; } else if (state == ListEditState.CALL_RECORD_FOLDER) { itemsStrings = new String[] { searchStr }; } else { Log.e(TAG, "Wrong state:" + mState); } final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_activated_1, android.R.id.text1, itemsStrings); mNavigationListView.setAdapter(arrayAdapter); mNavigationListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String curItemStr = arrayAdapter.getItem(position); if (createNewStr.equals(curItemStr)) { createNewNote(); } else if (createFolderStr.equals(curItemStr)) { showCreateOrModifyFolderDialog(true); } else if (exportTextStr.equals(curItemStr)) { exportNoteToText(); } else if (syncStr.equals(curItemStr) || cancelSyncStr.equals(curItemStr)) { if (isSyncMode()) { //TODO:??? if (TextUtils.equals(curItemStr, syncStr)) { GTaskSyncService.startSync(NotesListActivity.this); } else { GTaskSyncService.cancelSync(NotesListActivity.this); } } else { startPreferenceActivity(); } } else if (searchStr.equals(curItemStr)) { onSearchRequested(); } else if (setStr.equals(curItemStr)) { startPreferenceActivity(); } closeDrawerLayout(); } }); }
From source file:org.sufficientlysecure.keychain.ui.dialog.CreateKeyDialogFragment.java
private void setKeyLengthSpinnerValuesForAlgorithm(int algorithmId) { final ArrayAdapter<CharSequence> keySizeAdapter = (ArrayAdapter<CharSequence>) mKeySizeSpinner.getAdapter(); final Object selectedItem = mKeySizeSpinner.getSelectedItem(); keySizeAdapter.clear();//ww w . j a v a 2s .c o m switch (algorithmId) { case Constants.choice.algorithm.rsa: replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_rsa)); break; case Constants.choice.algorithm.elgamal: replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values); mCustomKeyInfoTextView.setText(""); // ElGamal does not support custom key length break; case Constants.choice.algorithm.dsa: replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_dsa)); break; } keySizeAdapter.notifyDataSetChanged(); // when switching algorithm, try to select same key length as before for (int i = 0; i < keySizeAdapter.getCount(); i++) { if (selectedItem.equals(keySizeAdapter.getItem(i))) { mKeySizeSpinner.setSelection(i); break; } } }
From source file:qauth.djd.qauthclient.main.ContentFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Bundle args = getArguments();/*from w w w.j av a2s . c om*/ if (args.getCharSequence(KEY_TITLE).toString().equals("Providers")) { View rootView = inflater.inflate(R.layout.providers_view_frag, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER; if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState .getSerializable(KEY_LAYOUT_MANAGER); } setRecyclerViewLayoutManager(mCurrentLayoutManagerType); pAdapter = new ProviderAdapter(pDataset); mRecyclerView.setAdapter(pAdapter); final PackageManager pm = getActivity().getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo packageInfo : packages) { //Log.i(TAG, "Installed package :" + packageInfo.packageName); //Log.i(TAG, "Source dir : " + packageInfo.sourceDir); //Log.i(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)); if (packageInfo.packageName.equals("qauth.djd.dummyclient")) { Provider provider = new Provider("DummyClient", packageInfo.packageName); pDataset.add(provider); pAdapter.notifyDataSetChanged(); } } //get local package names and cross reference with providers on server ("/provider/available") //display package names in listview //allow user to click on item to activate or deactivate // '-> have check box with progress bar indicating status return rootView; } else { View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); mLayoutManager = new LinearLayoutManager(getActivity()); mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER; if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState .getSerializable(KEY_LAYOUT_MANAGER); } setRecyclerViewLayoutManager(mCurrentLayoutManagerType); wAdapter = new WatchAdapter(wDataset); mRecyclerView.setAdapter(wAdapter); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab); fab.attachToRecyclerView(mRecyclerView); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i("test", "clicked!"); AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle("Select Bluetooth Device"); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_singlechoice); new Thread(new Runnable() { public void run() { for (String s : getNodes()) { arrayAdapter.add(s); } } }).start(); builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String nodeId = arrayAdapter.getItem(which); String privKey = null; String pubKey = null; try { SecureRandom random = new SecureRandom(); RSAKeyGenParameterSpec spec = new RSAKeyGenParameterSpec(1024, RSAKeyGenParameterSpec.F4); KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", "SC"); generator.initialize(spec, random); KeyPair pair = generator.generateKeyPair(); privKey = Base64.encodeToString(pair.getPrivate().getEncoded(), Base64.DEFAULT); pubKey = Base64.encodeToString(pair.getPublic().getEncoded(), Base64.DEFAULT); } catch (Exception e) { Log.i("generate", "error: " + e); } //Log.i("keys", "priv key : " + privKey); //String privKey = Base64.encodeToString(MainTabsActivity.privKey.getEncoded(), Base64.DEFAULT); //String pubKey = Base64.encodeToString(MainTabsActivity.pubKey.getEncoded(), Base64.DEFAULT); Keys keys = new Keys(privKey, pubKey); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); } catch (Exception e) { } try { out.writeObject(keys); } catch (Exception e) { } byte b[] = bos.toByteArray(); try { out.close(); } catch (Exception e) { } try { bos.close(); } catch (Exception e) { } Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, "REGISTER", b) .setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { Log.i("MessageApi", "Failed to send message with status code: " + sendMessageResult.getStatus().getStatusCode()); } else if (sendMessageResult.getStatus().isSuccess()) { Log.i("MessageApi", "onResult successful!"); } } }); } }); builderSingle.show(); } }); mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addConnectionCallbacks(this) .addOnConnectionFailedListener( new com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult result) { Log.i("mGoogleApiClient", "onConnectionFailed: " + result); } }) // Request access only to the Wearable API .addApi(Wearable.API).build(); mGoogleApiClient.connect(); /*BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); for(BluetoothDevice bt : pairedDevices) Log.i("BluetoothDevice", "pairedDevice: " + bt.toString());*/ return rootView; } }