List of usage examples for android.widget ArrayAdapter getItem
@Override public @Nullable T getItem(int position)
From source file:com.hitachi_tstv.yodpanom.yaowaluk.tiresmanagement.CheckListActivity.java
public static String[] getStringArray(ArrayAdapter adapter) { String[] a = new String[adapter.getCount()]; for (int i = 0; i < a.length; i++) a[i] = adapter.getItem(i).toString(); return a;/*from www .j a v a 2 s . c o m*/ }
From source file:com.poloure.simplerss.Utilities.java
static void setTitlesAndDrawerAndPage(Fragment fragment, int absolutePos) { String[] navTitles = s_resources.getStringArray(R.array.navigation_titles); if (null != fragment) { switchToFragment(fragment, false); }/*from w w w . ja v a 2s . c om*/ ListView list = s_fragmentDrawer.m_listView; HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) list.getAdapter(); int headers = headerAdapter.getHeadersCount(); int listPosition = -10 == absolutePos ? s_viewPager.getCurrentItem() + headers : absolutePos; int viewPagerPos = -10 == absolutePos ? s_viewPager.getCurrentItem() : absolutePos - headers; // Check the drawer item. String title = PagerAdapterTags.s_tagList.get(0); String subTitle = null; int imageRes = R.drawable.ic_action_labels; if (s_fragmentFavourites.isVisible()) { listPosition = 0; title = navTitles[0]; imageRes = R.drawable.ic_action_important; } else if (s_fragmentManage.isVisible()) { listPosition = 1; title = navTitles[1]; imageRes = R.drawable.ic_action_storage; } else if (s_fragmentSettings.isVisible()) { listPosition = 2; title = navTitles[2]; imageRes = R.drawable.ic_action_settings; } else { ArrayAdapter<String[]> adapter = (ArrayAdapter<String[]>) headerAdapter.getWrappedAdapter(); if (null != adapter && 0 < adapter.getCount()) { String[] item = adapter.getItem(viewPagerPos); title = item[0]; int count = null == item[1] || item[1].isEmpty() ? 0 : Integer.parseInt(item[1]); String countString = s_resources.getQuantityString(R.plurals.actionbar_subtitle_unread, count, count); subTitle = 0 == count ? null : countString; } } s_actionBar.setTitle(title); s_actionBar.setSubtitle(subTitle); s_actionBar.setIcon(imageRes); list.setItemChecked(listPosition, true); // If we must change the view pager page. if (0 <= viewPagerPos) { // Switch the view pager page if different. if (s_viewPager.getCurrentItem() != viewPagerPos) { s_viewPager.setCurrentItem(viewPagerPos); } } }
From source file:de.damdi.fitness.activity.SelectWorkoutDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // get Workouts IDataProvider dataProvider = new DataProvider(getActivity()); final List<Workout> workoutList = dataProvider.getWorkouts(); AlertDialog.Builder builder_workoutchooser = new AlertDialog.Builder(getActivity()); builder_workoutchooser.setTitle(getString(R.string.choose_workout)); final ArrayAdapter<Workout> adapter = new ArrayAdapter<Workout>(getActivity(), android.R.layout.select_dialog_singlechoice, workoutList); mCreatedDialog = builder_workoutchooser.setSingleChoiceItems(adapter, 0, new OnClickListener() { @Override/*from ww w .j a va2s . co m*/ public void onClick(DialogInterface dialog, int which) { mWorkout = adapter.getItem(which); // disable button for loading old training if (mWorkout.getFitnessExercises().get(0).getTrainingEntryList().isEmpty()) { disableButton(); } else { enableButton(); } } }).setPositiveButton(getString(R.string.start_new_training), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startTraining(true); } }).setNegativeButton(getString(R.string.load_old_training), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startTraining(false); } }).create(); return mCreatedDialog; }
From source file:de.skubware.opentraining.activity.SelectWorkoutDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // get Workouts IDataProvider dataProvider = new DataProvider(getActivity()); final List<Workout> workoutList = dataProvider.getWorkouts(); AlertDialog.Builder builder_workoutchooser = new AlertDialog.Builder(getActivity()); builder_workoutchooser.setTitle(getString(R.string.choose_workout)); final ArrayAdapter<Workout> adapter = new ArrayAdapter<Workout>(getActivity(), android.R.layout.select_dialog_singlechoice, workoutList); mCreatedDialog = builder_workoutchooser.setSingleChoiceItems(adapter, 0, new OnClickListener() { @Override/*ww w . ja v a 2 s . c o m*/ public void onClick(DialogInterface dialog, int which) { mWorkout = adapter.getItem(which); enableButton(); // disable button for loading old training if there is at least one exercise that has no history // this can happen when: // - there has never been any training before // - an exercise has been added (workout has been edited) for (FitnessExercise fEx : mWorkout.getFitnessExercises()) { if (fEx.getTrainingEntryList().isEmpty()) { disableButton(); break; } } } }).setPositiveButton(getString(R.string.start_new_training), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startTraining(true); } }).setNegativeButton(getString(R.string.load_old_training), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startTraining(false); } }).create(); return mCreatedDialog; }
From source file:com.github.andrewlord1990.snackbarbuildersample.SampleActivity.java
private ListAdapter createAdapter() { final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); listView.setOnItemClickListener(new OnItemClickListener() { @Override/*from w ww . ja v a2 s. co m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String item = adapter.getItem(position); samples.get(item).onClick(view); } }); for (String sample : samples.keySet()) { adapter.add(sample); } return adapter; }
From source file:net.tacks_a.ankicard.fragment.ExamCondFragment.java
private void setQuestionCountToAdapter() { LogUtil.logDebug();// w w w . jav a2 s.c om // Spinner? ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.ary_question_count, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpnQuestionCount.setAdapter(adapter); // ?? for (int i = 0; i < adapter.getCount(); i++) { String str1 = adapter.getItem(i).toString(); String str2 = Integer.toString(mExamCond.getQuestionCount()); if (str1.equals(str2)) { mSpnQuestionCount.setSelection(i); } } }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.CalibrateListActivity.java
/** * Load the calibrated swatches from the calibration text file * * @param callback callback to be initiated once the loading is complete *//*from ww w. j a v a2s. c o m*/ private void loadCalibration(@NonNull final Context context, @NonNull final Handler.Callback callback) { try { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, R.layout.row_text); final File path = FileHelper.getFilesDir(FileHelper.FileType.CALIBRATION, CaddisflyApp.getApp().getCurrentTestInfo().getId()); File[] listFilesTemp = null; if (path.exists() && path.isDirectory()) { listFilesTemp = path.listFiles(); } final File[] listFiles = listFilesTemp; if (listFiles != null && listFiles.length > 0) { Arrays.sort(listFiles); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); try { final List<Swatch> swatchList = SwatchHelper.loadCalibrationFromFile(getBaseContext(), fileName); (new AsyncTask<Void, Void, Void>() { @Nullable @Override protected Void doInBackground(Void... params) { SwatchHelper.saveCalibratedSwatches(context, swatchList); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } catch (Exception ex) { AlertUtil.showError(context, R.string.error, getString(R.string.errorLoadingFile), null, R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }, null, null); } } }); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alertDialog.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtil.askQuestion(context, R.string.delete, R.string.deleteConfirm, R.string.delete, R.string.cancel, true, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtil.deleteFile(path, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); alertDialog.dismiss(); Toast.makeText(context, R.string.deleted, Toast.LENGTH_SHORT) .show(); } }, null); return true; } }); } }); alertDialog.show(); } else { AlertUtil.showMessage(context, R.string.notFound, R.string.loadFilesNotAvailable); } } catch (ActivityNotFoundException ignored) { } callback.handleMessage(null); }
From source file:io.realm.examples.newsreader.ui.main.MainActivity.java
/** * Setup the toolbar spinner with the available sections *//*from w w w. j av a 2 s . c om*/ public void configureToolbar(List<String> sections) { String[] sectionList = sections.toArray(new String[sections.size()]); final ArrayAdapter adapter = new ArrayAdapter<CharSequence>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, sectionList); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { presenter.titleSpinnerSectionSelected((String) adapter.getItem(position)); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:de.uni_koblenz_landau.apow.SettingsFragment.java
/** * Called by settings task, when loading is finished. *///from w w w . j av a2s. c om @Override public void onSettingsFetched(ListViewItem settings, List<ListViewItem> locations) { mSettingsTask = null; // If result is not empty, update UI, else show error message. if (settings != null && locations != null) { mSettings = settings; mUsernameView.setText(mSettings.getField1()); mPasswordView.setText(mSettings.getField2()); mLocations = locations; ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, locations); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mLocationsView.setAdapter(adapter); int position = -1; for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).getId() == settings.getId()) { position = i; break; } } mLocationsView.setSelection(position); } else { Toast.makeText(getActivity(), R.string.error_database, Toast.LENGTH_SHORT).show(); } }
From source file:com.spatialnetworks.fulcrum.widget.DynamicListView.java
private void swapElements(int indexOne, int indexTwo) { ListAdapter listAdapter = getAdapter(); if (listAdapter instanceof WrapperListAdapter) { WrapperListAdapter wrapperListAdapter = (WrapperListAdapter) listAdapter; listAdapter = wrapperListAdapter.getWrappedAdapter(); }//from ww w.java 2 s .co m if (!(listAdapter instanceof ArrayAdapter)) { throw new RuntimeException("DynamicListView can only swap elements using an ArrayAdapter"); } else { ArrayAdapter arrayAdapter = (ArrayAdapter) listAdapter; Object obj2 = arrayAdapter.getItem(indexTwo); //noinspection unchecked arrayAdapter.remove(obj2); //noinspection unchecked arrayAdapter.insert(obj2, indexOne); } }