Java Code Examples for android.widget.AdapterView#getPositionForView()

The following examples show how to use android.widget.AdapterView#getPositionForView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: bilibili.java    From stynico with MIT License 6 votes vote down vote up
/**
    * Send a click event if parent view is a Listview instance
    *
    * @param isLongClick Is the event a long click ?
    */
   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);
           }
       }
   }
 
Example 2
Source File: RippleView.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
/**
 * Send a click event if parent view is a Listview instance
 *
 * @param isLongClick Is the event a long click ?
 */
private void sendClickEvent(final Boolean isLongClick) {
    if (getParent() instanceof AdapterView) {
        System.out.println("ripple>>>>>>>>>>>>>>");
        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);
        }
    }
}
 
Example 3
Source File: SwipeLayout.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * if working in {@link android.widget.AdapterView}, we should response
 * {@link android.widget.Adapter} isEnable(int position).
 *
 * @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;
}
 
Example 4
Source File: SwipeLayoutConv.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * if working in {@link AdapterView}, we should response
 * {@link Adapter} isEnable(int position).
 *
 * @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(SwipeLayoutConv.this);
            if (adapter instanceof BaseAdapter) {
                enable = ((BaseAdapter) adapter).isEnabled(p);
            } else if (adapter instanceof ListAdapter) {
                enable = ((ListAdapter) adapter).isEnabled(p);
            }
        }
    }
    return enable;
}
 
Example 5
Source File: SwipeLayout.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * if working in {@link android.widget.AdapterView}, we should response {@link android.widget.Adapter}
 * isEnable(int position).
 * @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;
}
 
Example 6
Source File: RippleView.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Send a click event if parent view is a Listview instance
 *
 * @param isLongClick Is the event a long click ?
 */
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);
            }
        }
    }
}
 
Example 7
Source File: ZSwipeItem.java    From ZListVIew with Apache License 2.0 6 votes vote down vote up
private void performAdapterViewItemClick(MotionEvent e) {
	ViewParent t = getParent();

	Log.d(TAG, "performAdapterViewItemClick()");

	while (t != null) {
		if (t instanceof AdapterView) {
			@SuppressWarnings("rawtypes")
			AdapterView view = (AdapterView) t;
			int p = view.getPositionForView(ZSwipeItem.this);
			if (p != AdapterView.INVALID_POSITION
					&& view.performItemClick(
							view.getChildAt(p
									- view.getFirstVisiblePosition()), p,
							view.getAdapter().getItemId(p)))
				return;
		} else {
			if (t instanceof View && ((View) t).performClick())
				return;
		}

		t = t.getParent();
	}
}
 
Example 8
Source File: ZSwipeItem.java    From AutoLoadListView with Apache License 2.0 6 votes vote down vote up
/**
 * if working in {@link android.widget.AdapterView}, we should response
 * {@link android.widget.Adapter} isEnable(int position).
 *
 * @return true when item is enabled, else disabled.
 */
private boolean isEnabledInAdapterView() {
	@SuppressWarnings("rawtypes")
	AdapterView adapterView = getAdapterView();
	boolean enable = true;
	if (adapterView != null) {
		Adapter adapter = adapterView.getAdapter();
		if (adapter != null) {
			int p = adapterView.getPositionForView(ZSwipeItem.this);
			if (adapter instanceof BaseAdapter) {
				enable = ((BaseAdapter) adapter).isEnabled(p);
			} else if (adapter instanceof ListAdapter) {
				enable = ((ListAdapter) adapter).isEnabled(p);
			}
		}
	}
	return enable;
}
 
Example 9
Source File: SwipeLayout.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void performAdapterViewItemClick(MotionEvent e){
    ViewParent t = getParent();
    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();
    }
}
 
Example 10
Source File: SwipeLayout.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
private boolean performAdapterViewItemLongClick() {
    if (getOpenStatus() != Status.Close) return false;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p == AdapterView.INVALID_POSITION) return false;
        long vId = view.getItemIdAtPosition(p);
        boolean handled = false;
        try {
            Method m = AbsListView.class.getDeclaredMethod("performLongPress", View.class, int.class, long.class);
            m.setAccessible(true);
            handled = (boolean) m.invoke(view, SwipeLayout.this, p, vId);

        } catch (Exception e) {
            e.printStackTrace();

            if (view.getOnItemLongClickListener() != null) {
                handled = view.getOnItemLongClickListener().onItemLongClick(view, SwipeLayout.this, p, vId);
            }
            if (handled) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
        return handled;
    }
    return false;
}
 
Example 11
Source File: MaterialRippleLayout.java    From LoyalNativeSlider with MIT License 5 votes vote down vote up
private void clickAdapterView(AdapterView parent) {
    final int position = parent.getPositionForView(MaterialRippleLayout.this);
    final long itemId = parent.getAdapter() != null
            ? parent.getAdapter().getItemId(position)
            : 0;
    if (position != AdapterView.INVALID_POSITION) {
        parent.performItemClick(MaterialRippleLayout.this, position, itemId);
    }
}
 
Example 12
Source File: SwipeViewLayout.java    From UltimateSwipeTool with Apache License 2.0 5 votes vote down vote up
private boolean performAdapterViewItemLongClick() {
    if (getOpenStatus() != Status.Close) return false;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeViewLayout.this);
        if (p == AdapterView.INVALID_POSITION) return false;
        long vId = view.getItemIdAtPosition(p);
        boolean handled = false;
        try {
            Method m = AbsListView.class.getDeclaredMethod("performLongPress", View.class, int.class, long.class);
            m.setAccessible(true);
            handled = (boolean) m.invoke(view, SwipeViewLayout.this, p, vId);

        } catch (Exception e) {
            e.printStackTrace();

            if (view.getOnItemLongClickListener() != null) {
                handled = view.getOnItemLongClickListener().onItemLongClick(view, SwipeViewLayout.this, p, vId);
            }
            if (handled) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
        return handled;
    }
    return false;
}
 
Example 13
Source File: RippleView.java    From Conquer with Apache License 2.0 5 votes vote down vote up
/**
 * Send a click event if parent view is a Listview instance
 *
 * @param isLongClick Is the event a long click ?
 */
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);
        }
    }
}
 
Example 14
Source File: SwipeLayout.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
private void performAdapterViewItemClick() {
    if (getOpenStatus() != Status.Close) return;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p != AdapterView.INVALID_POSITION) {
            view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view
                    .getAdapter().getItemId(p));
        }
    }
}
 
Example 15
Source File: RippleView.java    From MaterialPageStateLayout with MIT License 5 votes vote down vote up
/**
 * Send a click event if parent view is a Listview instance
 *
 * @param isLongClick Is the event a long click ?
 */
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);
        }
    }
}
 
Example 16
Source File: MaterialRippleLayoutNineOld.java    From KickAssSlidingMenu with Apache License 2.0 5 votes vote down vote up
private void clickAdapterView(AdapterView parent) {
    final int position = parent.getPositionForView(MaterialRippleLayoutNineOld.this);
    final long itemId = parent.getAdapter() != null
            ? parent.getAdapter().getItemId(position)
            : 0;
    if (position != AdapterView.INVALID_POSITION) {
        parent.performItemClick(MaterialRippleLayoutNineOld.this, position, itemId);
    }
}
 
Example 17
Source File: SwipeLayout.java    From StickyListHeadersWithRefreshAndLoadMore with Apache License 2.0 5 votes vote down vote up
private boolean performAdapterViewItemLongClick() {
    if (getOpenStatus() != Status.Close) return false;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p == AdapterView.INVALID_POSITION) return false;
        long vId = view.getItemIdAtPosition(p);
        boolean handled = false;
        try {
            Method m = AbsListView.class.getDeclaredMethod("performLongPress", View.class, int.class, long.class);
            m.setAccessible(true);
            handled = (boolean) m.invoke(view, SwipeLayout.this, p, vId);

        } catch (Exception e) {
            e.printStackTrace();

            if (view.getOnItemLongClickListener() != null) {
                handled = view.getOnItemLongClickListener().onItemLongClick(view, SwipeLayout.this, p, vId);
            }
            if (handled) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
        return handled;
    }
    return false;
}
 
Example 18
Source File: SwipeLayout.java    From AndroidSwipeLayout with MIT License 5 votes vote down vote up
private boolean performAdapterViewItemLongClick() {
    if (getOpenStatus() != Status.Close) return false;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p == AdapterView.INVALID_POSITION) return false;
        long vId = view.getItemIdAtPosition(p);
        boolean handled = false;
        try {
            Method m = AbsListView.class.getDeclaredMethod("performLongPress", View.class, int.class, long.class);
            m.setAccessible(true);
            handled = (boolean) m.invoke(view, SwipeLayout.this, p, vId);

        } catch (Exception e) {
            e.printStackTrace();

            if (view.getOnItemLongClickListener() != null) {
                handled = view.getOnItemLongClickListener().onItemLongClick(view, SwipeLayout.this, p, vId);
            }
            if (handled) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
        return handled;
    }
    return false;
}
 
Example 19
Source File: RippleView.java    From DoubanTop with Apache License 2.0 5 votes vote down vote up
/**
 * Send a click event if parent view is a Listview instance
 *
 * @param isLongClick Is the event a long click ?
 */
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);
        }
    }
}
 
Example 20
Source File: AdapterViewUtil.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * 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).
 */
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;
}