List of usage examples for android.widget AdapterView getPositionForView
public int getPositionForView(View view)
From source file:Main.java
/** * Get the position within the adapter's dataset for the view, where view is an adapter item or a descendant of an adapter item. * Unlike {@link AdapterView#getPositionForView(android.view.View)}, returned position will reflect the position of the item given view is representing, * by subtracting the header views count. * @param adapterView the AdapterView containing the view. * @param view an adapter item or a descendant of an adapter item. This must be visible in given AdapterView at the time of the call. * @return the position of the item in the AdapterView represented by given view, or {@link AdapterView#INVALID_POSITION} if the view does not * correspond to a list item (or it is not visible). */// w w w . j a v a 2s.c om public static int getPositionForView(final AdapterView<?> adapterView, final View view) { int position = adapterView.getPositionForView(view); if (adapterView instanceof ListView) { position -= ((ListView) adapterView).getHeaderViewsCount(); } return position; }
From source file:org.blanco.techmun.android.fragments.EventosListFragment.java
public void onItemClick(AdapterView<?> adapterView, View view, int pres, long time) { int position = adapterView.getPositionForView(view); Evento e = (Evento) eventosList.getAdapter().getItem(position); Intent intent = new Intent("org.blanco.techmun2011.COMENTARIOS"); intent.putExtra("evento", e); startActivity(intent);// w ww. j a va 2 s . co m }
From source file:com.android.andryyu.lifehelper.widget.RippleView.java
/** * Send a click event if parent view is a Listview instance * * @param isLongClick Is the event a long click ? *//*from ww w . ja v a 2 s . c o m*/ private void sendClickEvent(final Boolean isLongClick) { if (getParent() instanceof AdapterView) { final AdapterView adapterView = (AdapterView) getParent(); final int position = adapterView.getPositionForView(this); final long id = adapterView.getItemIdAtPosition(position); if (isLongClick) { if (adapterView.getOnItemLongClickListener() != null) adapterView.getOnItemLongClickListener().onItemLongClick(adapterView, this, position, id); } else { if (adapterView.getOnItemClickListener() != null) adapterView.getOnItemClickListener().onItemClick(adapterView, this, position, id); } } }
From source file:com.grottworkshop.gwsswipelayout.SwipeLayout.java
private void performAdapterViewItemClick(MotionEvent e) { ViewParent t = getParent();/*from w w w .j a v a2 s. c o m*/ 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.grottworkshop.gwsswipelayout.SwipeLayout.java
/** * if working in {@link android.widget.AdapterView}, we should response {@link android.widget.Adapter} * isEnable(int position).//from ww w. ja v a2 s . c om * @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; }