List of usage examples for android.widget AdapterView getAdapter
public abstract T getAdapter();
From source file:de.uulm.graphicalpasswords.openuyi.UYICreatePasswordActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uyi_create_password); // Show the Up button in the action bar. setupActionBar();//w w w .j a va2s. c o m SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); length = Integer.parseInt(sharedPref.getString("uyi_length", "10")); originalViews = new ImageView[length]; distortedViews = new ImageView[length]; selectedPictures = new Picture[length]; Bundle bundle = new Bundle(); bundle.putInt("length", length); DialogFragment intro = new IntroDialogFragment(); intro.setArguments(bundle); intro.show(getFragmentManager(), "intro"); vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE); Arrays.fill(selectedPictures, null); gallery = (Gallery) findViewById(R.id.uyi_gallery_originals); gallery.setAdapter(new UYIImageAdapter(this)); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ImageView viewOriginal = new ImageView(UYICreatePasswordActivity.this); ImageView viewDistorted = new ImageView(UYICreatePasswordActivity.this); int i = 0; for (; i < selectedPictures.length; i++) { if (i == selectedPictures.length - 1 && selectedPictures[i] != null) { removePicture(i); } if (selectedPictures[i] == null || i == selectedPictures.length - 1) { viewOriginal = originalViews[i]; viewDistorted = distortedViews[i]; selectedPictures[i] = ((UYIImageAdapter) parent.getAdapter()).getPicture(position); vibrator.vibrate(100); ScrollView sv = (ScrollView) findViewById(R.id.uyi_choosepi_scrollview); int height = originalViews[0].getMeasuredHeight(); sv.scrollTo(0, (i * height) - 200); break; } } int originalImageResource = ((UYIImageAdapter) parent.getAdapter()).getImageResource(position); viewOriginal.setImageResource(originalImageResource); viewDistorted.setImageResource( ((UYIImageAdapter) parent.getAdapter()).getDistortedImageResource(position)); ((UYIImageAdapter) parent.getAdapter()).removePicture(position); OnLongClickListener listener = new OnLongClickListener() { @Override public boolean onLongClick(View v) { vibrator.vibrate(200); int viewid = v.getId(); int index = -1; for (int i = 0; i < originalViews.length; i++) { if (originalViews[i].getId() == viewid) { index = i; break; } else if (distortedViews[i].getId() == viewid) { index = i; break; } } Bundle bundle = new Bundle(); bundle.putInt("index", index); DialogFragment dialog = new DeleteImageDialogFragment(); dialog.setArguments(bundle); dialog.show(getFragmentManager(), "delete"); return false; } }; viewOriginal.setOnLongClickListener(listener); viewDistorted.setOnLongClickListener(listener); // Check int count = 0; for (int j = 0; j < selectedPictures.length; j++) { if (selectedPictures[j] != null) { count++; } } if (count == selectedPictures.length) { findViewById(R.id.uyi_save).setClickable(true); findViewById(R.id.uyi_save).setEnabled(true); } } }); table = (TableLayout) findViewById(R.id.uyi_choosepi_tablelayout); LayoutParams params = new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT, android.widget.TableRow.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER; for (int i = 0; i < length; i++) { TableRow row = new TableRow(table.getContext()); originalViews[i] = new ImageView(row.getContext()); originalViews[i].setAdjustViewBounds(true); originalViews[i].setScaleType(ScaleType.FIT_XY); originalViews[i].setPadding(3, 3, 3, 3); originalViews[i].setImageResource(R.drawable.oempty); originalViews[i].setId(100 + i); distortedViews[i] = new ImageView(row.getContext()); distortedViews[i].setAdjustViewBounds(true); distortedViews[i].setScaleType(ScaleType.FIT_XY); distortedViews[i].setPadding(3, 3, 3, 3); distortedViews[i].setImageResource(R.drawable.wempty); distortedViews[i].setId(1000 + i); ImageView arrow = new ImageView(row.getContext()); arrow.setAdjustViewBounds(true); arrow.setScaleType(ScaleType.FIT_XY); arrow.setMaxWidth(80); arrow.setPadding(3, 3, 3, 3); arrow.setImageResource(R.drawable.arrow_active); arrow.setLayoutParams(params); row.addView(originalViews[i]); row.addView(arrow); row.addView(distortedViews[i]); table.addView(row); } }
From source file:com.tencent.wstt.gt.activity.GTLogFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View logLayout = inflater.inflate(R.layout.gt_logactivity, container, false); displayWidth = DeviceUtils.getDisplayWidth(getActivity()); rl_log_filter = (RelativeLayout) logLayout.findViewById(R.id.rl_log_filter); cb_logcatSwitch = (GTCheckBox) logLayout.findViewById(R.id.cb_logcat_switch); cb_logcatSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//ww w .ja v a2s .c o m public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // TODO logcat? logcatTask = new LogcatRunnable(); new Thread(logcatTask).start(); } else { logcatTask.killReader(); } } }); btn_delete = (ImageButton) logLayout.findViewById(R.id.gtlog_delete); btn_save = (ImageButton) logLayout.findViewById(R.id.gtlog_save); btn_open = (ImageButton) logLayout.findViewById(R.id.gtlog_open); btn_level_toast = (ImageButton) logLayout.findViewById(R.id.log_level_toast); btn_tag_toast = (ImageButton) logLayout.findViewById(R.id.log_tag_toast); /* * ??ImageView ??filterListViewfilterListView */ img_empty = (ImageView) logLayout.findViewById(R.id.view_empty); img_empty.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { img_empty.setVisibility(View.GONE); filterListView.setVisibility(View.GONE); cancelFilterMsgInput(v); return false; } }); /* * ? */ RelativeLayout rl_save = (RelativeLayout) LayoutInflater.from(getActivity()) .inflate(R.layout.gt_dailog_save, null, false); ImageButton btn_cleanSavePath = (ImageButton) rl_save.findViewById(R.id.save_clean); btn_cleanSavePath.setOnClickListener(this); et_savePath = (EditText) rl_save.findViewById(R.id.save_editor); String lastSaveLog = GTLogInternal.getLastSaveLog(); if (lastSaveLog != null && lastSaveLog.contains(".") && lastSaveLog.endsWith(LogUtils.LOG_POSFIX)) { lastSaveLog = lastSaveLog.substring(0, lastSaveLog.lastIndexOf(".")); } et_savePath.setText(lastSaveLog); dlg_save = new Builder(getActivity()).setTitle(getString(R.string.save_file)).setView(rl_save) .setPositiveButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setNegativeButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // ?? String path = et_savePath.getText().toString(); try { File f = null; if (FileUtil.isPathStringValid(path)) { String validPath = FileUtil.convertValidFilePath(path, LogUtils.LOG_POSFIX); if (FileUtil.isPath(validPath)) { f = new File(validPath); f.mkdirs(); } else { f = new File(Env.ROOT_LOG_FOLDER, validPath); } GTLogInternal.setLastSaveLog(validPath); } if (f.exists()) { f.delete(); } LogUtils.writeLog(logAdapter.getUIEntryList(), f, false); } catch (Exception e) { e.printStackTrace(); } dialog.dismiss(); } }).create(); btn_save.setOnClickListener(this); // btn_delete.setOnClickListener(this); // btn_open.setOnClickListener(this); // rl_loglist = (RelativeLayout) logLayout.findViewById(R.id.rl_loglist); listView = (ListView) logLayout.findViewById(R.id.loglist); initCurLogAdapter(); logAdapter.setFilter(); listView.setAdapter(logAdapter); // button??? listView.setOnScrollListener(new OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { rl_log_filter.setVisibility(View.GONE); } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (visibleItemCount + firstVisibleItem == totalItemCount) { logAdapter.setAutoRefresh(true); } else { logAdapter.setAutoRefresh(false); } } }); // button? rl_loglist.setOnClickListener(this); listView.setOnTouchListener(logListTouchListener); // ? filterListView = (ListView) logLayout.findViewById(R.id.spinner_list); tagAdapter = new ArrayAdapter<String>(getActivity(), R.layout.gt_simple_dropdown_item); filterListView.setAdapter(tagAdapter); filterListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long arg3) { img_empty.setVisibility(View.GONE); filterListView.setVisibility(View.GONE); if (parent.getAdapter() == tagAdapter) { if (position == 0) GTLogInternal.setCurFilterTag(""); else GTLogInternal.setCurFilterTag((String) parent.getAdapter().getItem(position)); btn_tag.setText(tagAdapter.getItem(position)); } else if (parent.getAdapter() instanceof MsgAdaptor) { String sCurSelectedMsg = (String) parent.getAdapter().getItem(position); LinkedList<String> curShowDownMsgList = GTLogInternal.getCurFilterShowDownMsgList(); LinkedList<String> msgHistory = GTLogInternal.getCurFilterMsgHistory(); GTLogInternal.setCurFilterMsg(sCurSelectedMsg); msgWatched = false; et_Msg.removeTextChangedListener(msg_watcher); String s = curShowDownMsgList.remove(position); curShowDownMsgList.addFirst(s); msgHistory.remove(s); msgHistory.addFirst(s); et_Msg.setText(sCurSelectedMsg); btn_msg_clear.setVisibility(View.VISIBLE); cancelFilterMsgInput(parent); } else { GTLogInternal.setCurFilterLevel(position); btn_level.setText(levelAdapter.getItem(position)); } onLogChanged(); } }); // Activity??? GTLogInternal.addLogListener(this); // ? //btn_search = (ImageButton) findViewById(R.id.log_search); btn_search = (ImageButton) logLayout.findViewById(R.id.gtlog_search); btn_search.setOnClickListener(this); // btn_level = (Button) logLayout.findViewById(R.id.log_level); levelAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.log_level, R.layout.gt_simple_dropdown_item); btn_level.setText(levelAdapter.getItem(GTLogInternal.getCurFilterLevel())); btn_level.setOnClickListener(this); // TAG btn_tag = (Button) logLayout.findViewById(R.id.log_tag); if (GTLogInternal.getCurFilterTag().length() == 0) { btn_tag.setText("TAG"); } else { btn_tag.setText(GTLogInternal.getCurFilterTag()); } btn_tag.setOnClickListener(this); // et_Msg = (EditText) logLayout.findViewById(R.id.log_msg); et_Msg.setText(GTLogInternal.getCurFilterMsg()); et_Msg.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus && !logAdapter.isEmpty())// edit? { msgEtOnFocusOrClick(); } } }); et_Msg.setOnClickListener(this); et_Msg.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: // ?showdown? msgWatched = false; et_Msg.removeTextChangedListener(msg_watcher); String word = et_Msg.getText().toString(); if (!word.equals("")) { LinkedList<String> curShowDownMsgList = GTLogInternal.getCurFilterShowDownMsgList(); LinkedList<String> msgHistory = GTLogInternal.getCurFilterMsgHistory(); msgHistory.remove(word); msgHistory.addFirst(word); curShowDownMsgList.remove(word); curShowDownMsgList.addFirst(word); } filterListView.setVisibility(View.GONE); img_empty.setVisibility(View.GONE); cancelFilterMsgInput(v); return true; } return false; } }); // ? btn_msg_clear = (ImageButton) logLayout.findViewById(R.id.log_msg_clear); btn_msg_clear.setOnClickListener(this); if (et_Msg.getText().toString().length() > 0) { btn_msg_clear.setVisibility(View.VISIBLE); } else { btn_msg_clear.setVisibility(View.GONE); } // ? btn_msg_input_cancel = (Button) logLayout.findViewById(R.id.log_msg_cancel); btn_msg_input_cancel.setOnClickListener(this); handler = new Handler(); return logLayout; }
From source file:free.yhc.feeder.ChannelListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.channel_listview, null); mListView = (ListView) ll.findViewById(R.id.list); eAssert(null != mListView);/* www . ja va 2 s.co m*/ mListView.setAdapter(new ChannelListAdapter(getActivity(), ChannelListAdapter.getQueryCursor(mCatId), mListView, DATA_REQ_SZ, DATA_ARR_MAX, new AdapterActionListener())); mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long itemId) { if (getAdapter().isLoadingItem(position)) return; Intent intent = new Intent(getActivity(), ItemListActivity.class); intent.putExtra(ItemListActivity.IKEY_MODE, ItemListActivity.MODE_CHANNEL); intent.putExtra(ItemListActivity.IKEY_FILTER, ItemListActivity.FILTER_NONE); intent.putExtra("cid", ((ChannelListAdapter) parent.getAdapter()).getItemInfo_cid(position)); startActivity(intent); } }); ScrollView sv = (ScrollView) ll.findViewById(R.id.empty_list); mListView.setEmptyView(sv); setToPrimary(mPrimary); return ll; }
From source file:com.juick.android.MessageMenu.java
public boolean onItemLongClick(final AdapterView parent, View view, final int position, long id) { menuActions.clear();//from w w w. j av a 2 s .co m listSelectedItem = (JuickMessage) parent.getAdapter().getItem(position); JuickMessage secondaryItem = null; float x = JuickAdvancedApplication.getLastTouchX(); float y = JuickAdvancedApplication.getLastTouchY(); if (listSelectedItem.contextPost != null) { secondaryItem = listSelectedItem.contextPost; } urls = new ArrayList<String>(); if (listSelectedItem.Photo != null) { urls.add(listSelectedItem.Photo); } if (listSelectedItem.Video != null) { urls.add(listSelectedItem.Video); } collectURLs(listSelectedItem.Text, listSelectedItem.getMID()); if (secondaryItem != null) { collectURLs(secondaryItem.Text, listSelectedItem.getMID()); } if (urls.size() > 0) { HashSet<String> added = new HashSet<String>(); for (final String url : urls) { // filter out crap if (url.endsWith("hqdefault.jpg") && url.contains("youtube")) continue; // deduplicate if (added.add(url)) { menuActions.add(new RunnableItem(url) { @Override public void run() { launchURL(listSelectedItem.getMID(), url); } }); } } } collectMenuActions(); // Censor - Submit a token for review TextView listSelectedTextView = (TextView) view.findViewById(R.id.text); int[] loc2 = new int[2]; listSelectedTextView.getLocationOnScreen(loc2); int[] loc1 = new int[2]; listView.getLocationOnScreen(loc1); y -= loc2[1] - loc1[1]; x -= loc2[0] - loc1[0]; int offset = getOffsetForPosition(listSelectedTextView, x, y); if (offset != -1 && false) { final String text = listSelectedTextView.getText().toString(); final String word = Utils.getWordAtOffset(text, offset); if (word != null) { menuActions.add(new RunnableItem( activity.getResources().getString(R.string.CensorSubmitTokenForReview1) + " \"" + word + "\" " + activity.getResources().getString(R.string.CensorSubmitTokenForReview2)) { @Override public void run() { actionSubmitTokenForReview(word); } }); } else { Toast.makeText(activity, activity.getResources().getString(R.string.CensorSubmitWordSelectionError), Toast.LENGTH_LONG).show(); } } runActions(); return true; }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to the user for the browser bookmarks. Allow the user to add a * browser bookmark to an existing row or a new row. * //from w w w.j a v a 2 s . c om * @param context */ public static void displayAddBrowserBookmark(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_browser_bookmarks_list); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); ListView listView = (ListView) dialog.findViewById(R.id.list); final ArrayList<BookmarkInfo> bookmarks = loadBookmarks(context); Collections.sort(bookmarks, new Comparator<BookmarkInfo>() { @Override public int compare(BookmarkInfo lhs, BookmarkInfo rhs) { return lhs.getTitle().toLowerCase().compareTo(rhs.getTitle().toLowerCase()); } }); listView.setAdapter(new BookmarkAdapter(context, bookmarks)); listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { // run in thread since network logic needed to get bookmark icon new Thread(new Runnable() { public void run() { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } boolean currentRow = !newRadioButton.isChecked(); try { BookmarkInfo bookmark = (BookmarkInfo) parent.getAdapter().getItem(position); int rowId = 0; int rowPosition = 0; if (currentRow) { rowId = context.getCurrentGalleryId(); ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId); rowPosition = items.size(); // in last // position // for selected // row } else { rowId = (int) RowsTable.insertRow(context, name, 0, RowInfo.FAVORITE_TYPE); rowPosition = 0; } Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(bookmark.getUrl())); Uri uri = Uri.parse(bookmark.getUrl()); Log.d(LOG_TAG, "host=" + uri.getScheme() + "://" + uri.getHost()); String icon = Utils.getWebSiteIcon(context, "http://" + uri.getHost()); Log.d(LOG_TAG, "icon1=" + icon); if (icon == null) { // try base host address int count = StringUtils.countMatches(uri.getHost(), "."); if (count > 1) { int index = uri.getHost().indexOf('.'); String baseHost = uri.getHost().substring(index + 1); icon = Utils.getWebSiteIcon(context, "http://" + baseHost); Log.d(LOG_TAG, "icon2=" + icon); } } ItemsTable.insertItem(context, rowId, rowPosition, bookmark.getTitle(), intent, icon, DatabaseHelper.SHORTCUT_TYPE); } catch (Exception e) { Log.e(LOG_TAG, "displayAddBrowserBookmark", e); } // need to do this on UI thread context.getHandler().post(new Runnable() { public void run() { context.showCover(false); dialog.dismiss(); context.reloadAllGalleries(); } }); if (currentRow) { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK); } else { Analytics.logEvent(Analytics.ADD_BROWSER_BOOKMARK_WITH_ROW); } } }).start(); } }); listView.setDrawingCacheEnabled(true); listView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_BROWSER_BOOKMARK); }
From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java
/** * if working in {@link android.widget.AdapterView}, we should response {@link android.widget.Adapter} * isEnable(int position).//from ww w. j a v a 2s. c o m * @return true when item is enabled, else disabled. */ private boolean isEnabledInAdapterView() { AdapterView adapterView = getAdapterView(); boolean enable = true; if (adapterView != null) { Adapter adapter = adapterView.getAdapter(); if (adapter != null) { int p = adapterView.getPositionForView(SwipeLayout.this); if (adapter instanceof BaseAdapter) { enable = ((BaseAdapter) adapter).isEnabled(p); } else if (adapter instanceof ListAdapter) { enable = ((ListAdapter) adapter).isEnabled(p); } } } return enable; }
From source file:com.brandroidtools.filemanager.fragments.NavigationFragment.java
/** * {@inheritDoc}//from w ww . j a va2 s . com */ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { try { FileSystemObject fso = ((FileSystemObjectAdapter) parent.getAdapter()).getItem(position); if (fso instanceof ParentDirectory) { changeCurrentDir(fso.getParent(), true, false, false, null, null); return; } else if (fso instanceof Directory) { changeCurrentDir(fso.getFullPath(), true, false, false, null, null); return; } else if (fso instanceof Symlink) { Symlink symlink = (Symlink) fso; if (symlink.getLinkRef() != null && symlink.getLinkRef() instanceof Directory) { changeCurrentDir(symlink.getLinkRef().getFullPath(), true, false, false, null, null); return; } // Open the link ref fso = symlink.getLinkRef(); } // Open the file (edit or pick) if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) { // Open the file with the preferred registered app IntentsActionPolicy.openFileSystemObject(mActivity, fso, false, null, null); } else { // Request a file pick selection if (this.mOnFilePickedListener != null) { this.mOnFilePickedListener.onFilePicked(fso); } } } catch (Throwable ex) { ExceptionUtil.translateException(mActivity, ex); } }
From source file:com.brandroidtools.filemanager.fragments.NavigationFragment.java
/** * Method that loads the files in the adapter. * * @param files The files to load in the adapter * @hide/*w w w . ja v a 2 s . c om*/ */ @SuppressWarnings("unchecked") private void loadData(final List<FileSystemObject> files) { //Notify data to adapter view final AdapterView<ListAdapter> view = (AdapterView<ListAdapter>) getView() .findViewById(RESOURCE_CURRENT_LAYOUT); FileSystemObjectAdapter adapter = (FileSystemObjectAdapter) view.getAdapter(); adapter.clear(); adapter.addAll(files); adapter.notifyDataSetChanged(); view.setSelection(0); }
From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java
private void performAdapterViewItemClick(MotionEvent e) { ViewParent t = getParent();//from ww w .j av a 2 s . c om while (t != null) { if (t instanceof AdapterView) { AdapterView view = (AdapterView) t; int p = view.getPositionForView(SwipeLayout.this); if (p != AdapterView.INVALID_POSITION && view.performItemClick(view.getChildAt(p), p, view.getAdapter().getItemId(p))) return; } else { if (t instanceof View && ((View) t).performClick()) return; } t = t.getParent(); } }
From source file:com.audiokernel.euphonyrmt.fragments.SongsFragment.java
@Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { // If in simple mode : add, replace and play the shown album. if (mApp.isInSimpleMode()) { mApp.oMPDAsyncHelper.execAsync(new Runnable() { @Override//from w ww .j a v a 2s. co m public void run() { try { mApp.oMPDAsyncHelper.oMPD.add(mAlbum, true, true); // Account for the list header int positionCorrection = 0; if (mList instanceof ListView) { positionCorrection = ((ListView) mList).getHeaderViewsCount(); } mApp.oMPDAsyncHelper.oMPD.seekByIndex(position - positionCorrection, 0l); } catch (final IOException | MPDException e) { Log.e(TAG, "Failed to seek by index.", e); } } }); } else { mApp.oMPDAsyncHelper.execAsync(new Runnable() { @Override public void run() { add((Item) parent.getAdapter().getItem(position), false, false); } }); } }