List of usage examples for android.widget Adapter getItem
Object getItem(int position);
From source file:Main.java
/** * * @param adapter - adapter with objects to be searched * @param object - object to search in adapter * @param defaultPosition - default position to return if object is not in adapter * @return position of item or default position if item is not in adapter *///ww w .j ava2 s .c om public static int getItemPosition(Adapter adapter, Object object, int defaultPosition) { int position = defaultPosition; for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).equals(object)) { position = i; break; } } return position; }
From source file:org.androidsoft.app.permission.ui.ApplicationsListFragment.java
/** * {@inheritDoc }//from ww w . ja v a2 s.c o m */ @Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Adapter adapter = l.getAdapter(); AppInfo app = (AppInfo) adapter.getItem(position); mContainerCallback.onAppSelected(app.getPackageName()); }
From source file:com.franceaoc.app.ui.fragment.NearestCommunesListFragment.java
/** * {@inheritDoc }/* w ww . j a v a 2 s.c o m*/ */ @Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Adapter adapter = l.getAdapter(); Commune commune = (Commune) adapter.getItem(position); mContainerCallback.onCommuneSelected(commune.getId()); }
From source file:com.codeherenow.navigationdrawer.NavigationDrawerActivity.java
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Show a toast Adapter adapter = parent.getAdapter(); String website = adapter.getItem(position).toString(); Toast.makeText(this, website, Toast.LENGTH_SHORT).show(); // Dismiss the drawer if (mDrawerLayout.isDrawerOpen(mDrawerListView)) { mDrawerLayout.closeDrawer(mDrawerListView); }//from w w w. j a v a 2 s .c o m }
From source file:org.lucasr.smoothie.samples.gallery.GalleryLoader.java
@Override public Long getItemParams(Adapter adapter, int position) { Cursor c = (Cursor) adapter.getItem(position); return c.getLong(c.getColumnIndex(ImageColumns._ID)); }
From source file:com.achep.acdisplay.ui.fragments.dialogs.SetupPermissionsDialog.java
@NonNull @Override/*from w ww . j a va 2 s.c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Context context = getActivity(); assert context != null; View view = new DialogBuilder(context).setTitle(R.string.permissions_dialog_title) .setView(R.layout.dialog_permissions).createSkeletonView(); // Make title more red TextView title = (TextView) view.findViewById(R.id.title); title.setTextColor(title.getCurrentTextColor() & 0xFFFF3333 | 0xFF << 16); ListView listView = (ListView) view.findViewById(R.id.list); mAdapter = new Adapter(context, new ArrayList<Item>()); listView.setAdapter(mAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Adapter adapter = (Adapter) parent.getAdapter(); Item item = adapter.getItem(position); item.run(); } }); return new AlertDialog.Builder(context).setView(view).setNeutralButton(R.string.later, null).create(); }
From source file:com.android.gallery3d2.ingest.IngestService.java
protected void importSelectedItems(SparseBooleanArray selected, Adapter adapter) { List<MtpObjectInfo> importHandles = new ArrayList<MtpObjectInfo>(); for (int i = 0; i < selected.size(); i++) { if (selected.valueAt(i)) { Object item = adapter.getItem(selected.keyAt(i)); if (item instanceof MtpObjectInfo) { importHandles.add(((MtpObjectInfo) item)); }/* ww w . ja v a 2 s .c o m*/ } } ImportTask task = new ImportTask(mDevice, importHandles, BucketNames.IMPORTED, this); task.setListener(this); mNotificationBuilder.setProgress(0, 0, true) .setContentText(getResources().getText(R.string.ingest_importing)); startForeground(NotificationIds.INGEST_NOTIFICATION_IMPORTING, mNotificationBuilder.build()); new Thread(task).start(); }
From source file:com.android.gallery3d.ingest.IngestService.java
protected void importSelectedItems(SparseBooleanArray selected, Adapter adapter) { List<IngestObjectInfo> importHandles = new ArrayList<IngestObjectInfo>(); for (int i = 0; i < selected.size(); i++) { if (selected.valueAt(i)) { Object item = adapter.getItem(selected.keyAt(i)); if (item instanceof IngestObjectInfo) { importHandles.add(((IngestObjectInfo) item)); }/*from w w w. j a v a 2s . c o m*/ } } ImportTask task = new ImportTask(mDevice, importHandles, mDevicePrettyName, this); task.setListener(this); mNotificationBuilder.setProgress(0, 0, true) .setContentText(getResources().getText(R.string.ingest_importing)); startForeground(R.id.ingest_notification_importing, mNotificationBuilder.build()); new Thread(task).start(); }
From source file:org.onepf.trivialdrive.ui.fragment.ProviderPickerDialogFragment.java
@NonNull @Override/* www. j a v a 2 s . c om*/ public Dialog onCreateDialog(final Bundle savedInstanceState) { if (listener == null) { throw new IllegalStateException(); } final OnProviderPickerListener listener = this.listener; final Adapter adapter = new Adapter(); final Dialog dialog = new AlertDialog.Builder(getActivity()).setCancelable(true) .setTitle(R.string.dialog_providers_title) .setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final Provider provider = adapter.getItem(which); listener.onProviderPicked(provider); dialog.dismiss(); } }).create(); dialog.setCanceledOnTouchOutside(true); return dialog; }
From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.widget.ListWidgetConfig.java
private int getSpinnerPositionOf(final Adapter adapter, final String entry) { if (adapter == null || adapter.getCount() == 0) return 0; int pos = 0;//www. j av a 2 s . co m for (int i = 0; i < adapter.getCount(); i++) { if (adapter.getItem(i).toString().equals(entry)) { pos = i; break; } } return pos; }