Java Code Examples for android.view.View.setOnLongClickListener()

The following are Jave code examples for showing how to use setOnLongClickListener() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: pipe   File: RecyclerAdapter.java   Source Code and License Vote up 6 votes
/**
 * 创建一个ViewHolder
 *
 * @param parent   RecyclerView
 * @param viewType 界面的类型,约定为XML布局的Id
 * @return ViewHolder
 */
@Override
public ViewHolder<Data> onCreateViewHolder(ViewGroup parent, int viewType) {
    // 得到LayoutInflater用于把XML初始化为View
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    // 把XML id为viewType的文件初始化为一个root View
    View root = inflater.inflate(viewType, parent, false);
    // 通过子类必须实现的方法,得到一个ViewHolder
    ViewHolder<Data> holder = onCreateViewHolder(root, viewType);


    // 设置View的Tag为ViewHolder,进行双向绑定
    root.setTag(R.id.tag_recycler_holder, holder);
    // 设置事件点击
    root.setOnClickListener(this);
    root.setOnLongClickListener(this);

    // 进行界面注解绑定
    holder.unbinder = ButterKnife.bind(holder, root);
    // 绑定callback
    holder.callback = this;

    return holder;
}
 
Example 2
Project: AndFast   File: BaseRecyclerAdapter.java   Source Code and License Vote up 6 votes
private void initItemClickListener(View convertView, final int position) {
    if (onRecyclerItemClickListener != null) {
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onRecyclerItemClickListener.onItemClick(v, position);
            }
        });
    }
    if (onRecyclerItemLongClickListener != null) {
        convertView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                return onRecyclerItemLongClickListener.onItemLongClick(view, position);
            }
        });
    }
}
 
Example 3
Project: GitHub   File: BaseViewHolder.java   Source Code and License Vote up 6 votes
/**
 * add long click view id
 *
 * @param viewId
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildLongClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
@SuppressWarnings("unchecked")
public BaseViewHolder addOnLongClickListener(@IdRes final int viewId) {
    itemChildLongClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isLongClickable()) {
            view.setLongClickable(true);
        }
        view.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return adapter.getOnItemChildLongClickListener() != null &&
                        adapter.getOnItemChildLongClickListener().onItemChildLongClick(adapter, v, getClickPosition());
            }
        });
    }
    return this;
}
 
Example 4
Project: android-advanced-light   File: HomeAdapter.java   Source Code and License Vote up 5 votes
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
    View view=LayoutInflater.from(
            mContext).inflate(R.layout.item_recycler, parent,
            false);
    MyViewHolder holder = new MyViewHolder(view);
    view.setOnClickListener(this);
    view.setOnLongClickListener(this);
    return holder;
}
 
Example 5
Project: YCBaseAdapter   File: BaseViewHolder.java   Source Code and License Vote up 5 votes
public BaseViewHolder(View itemView) {
    super(itemView);
    this.mItemView = itemView;
    itemView.setOnClickListener(this);
    itemView.setOnLongClickListener(this);
    viewSparseArray = new SparseArray<>();
}
 
Example 6
Project: DraggableTreeView   File: DraggableTreeView.java   Source Code and License Vote up 5 votes
public void createTreeItem(View view, final TreeNode node){
    if(view != null) {
        nodeOrder.add(node);
        final LinearLayout mItem = new LinearLayout(getContext());
        mItem.setOrientation(LinearLayout.VERTICAL);
        if(view.getParent() != null) {
            ViewGroup parent = (ViewGroup) view.getParent();
            parent.removeView(view);
        }
        view.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                mobileNode = node;
                addToView(mItem,node);
                mobileView = mItem;
                mDragItemCallback.onStartDrag(mobileNode.getView(),mobileNode);
                mItem.post(new Runnable() {
                    @Override
                    public void run() {
                        mCellIsMobile = true;
                        mHoverCell = getAndAddHoverView(mobileView,1f);
                        mobileView.setVisibility(INVISIBLE);
                    }
                });
                return false;
            }
        });
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(dpToPx(sideMargin*node.getLevel() ), 0, 0, 0 );
        mItem.setLayoutParams(layoutParams);
        mItem.addView(view);
        ((LinearLayout)adapter.root.getView()).addView(mItem);
    }
}
 
Example 7
Project: Idea-ChainSelector   File: ViewHolder.java   Source Code and License Vote up 5 votes
public ViewHolder setOnLongClickListener(int viewId,
                                         View.OnLongClickListener listener)
{
    View view = getView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
Example 8
Project: labtablet   File: DataListAdapter.java   Source Code and License Vote up 5 votes
public DataListVH(View rowView) {
    super(rowView);

    mDescriptorName = (TextView) rowView.findViewById(R.id.metadata_item_title);
    mDescriptorType = (ImageView) rowView.findViewById(R.id.metadata_item_type);
    mDescriptorValue = (TextView) rowView.findViewById(R.id.metadata_item_value);
    mDescriptorSize = (TextView) rowView.findViewById(R.id.metadata_item_size);
    mDescriptorDescription = (TextView) rowView.findViewById(R.id.metadata_item_description);
    mDataItemDeleteView = (LinearLayout) rowView.findViewById(R.id.ll_data_item_delete_view);

    rowView.setOnClickListener(this);
    rowView.setOnLongClickListener(this);
}
 
Example 9
Project: Ripple   File: MainActivity.java   Source Code and License Vote up 5 votes
/**
 * Set Android UI event handlers and connect to the RightMesh library when the
 * activity initializes.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    View buttonSend = findViewById(R.id.button_send);
    buttonSend.setOnClickListener(v -> sendMessage(target, colour));

    View buttonSendAll = findViewById(R.id.button_sendAll);
    buttonSendAll.setOnClickListener(v -> sendAll());

    // Display the RightMesh settings activity when the send button is tapped and held.
    buttonSend.setLongClickable(true);
    buttonSend.setOnLongClickListener(v -> {
        try {
            mm.showSettingsActivity();
        } catch (RightMeshException ignored) { /* Meh. */ }
        return true;
    });

    // Change the background colour when the respective colour buttons are pressed.
    findViewById(R.id.button_red).setOnClickListener(v -> setColour("RED"));
    findViewById(R.id.button_green).setOnClickListener(v -> setColour("GREEN"));
    findViewById(R.id.button_blue).setOnClickListener(v -> setColour("BLUE"));

    // Set up the recipient selection spinner.
    peersListAdapter = new MeshIDAdapter(this);
    component = (RightMeshRecipientComponent) getFragmentManager()
            .findFragmentById(R.id.recipient_component);
    component.setSpinnerAdapter(peersListAdapter);
    component.setOnRecipientChangedListener(this);

    // Initialize the RightMesh library with the SSID pattern "Ripple".
    mm = AndroidMeshManager.getInstance(MainActivity.this, MainActivity.this, "Ripple");
}
 
Example 10
Project: draggable-tree-itemview   File: DraggableTreeView.java   Source Code and License Vote up 5 votes
public void createTreeItem(View view, final TreeNode node){
    if(view != null) {
        nodeOrder.add(node);
        final LinearLayout mItem = new LinearLayout(getContext());
        mItem.setOrientation(LinearLayout.VERTICAL);
        if(view.getParent() != null) {
            ViewGroup parent = (ViewGroup) view.getParent();
            parent.removeView(view);
        }
        view.setOnLongClickListener(new OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                mobileNode = node;
                addToView(mItem,node);
                mobileView = mItem;
                mDragItemCallback.onStartDrag(mobileNode.getView(),mobileNode);
                mItem.post(new Runnable() {
                    @Override
                    public void run() {
                        mCellIsMobile = true;
                        mHoverCell = getAndAddHoverView(mobileView,1f);
                        mobileView.setVisibility(INVISIBLE);
                    }
                });
                return false;
            }
        });
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(dpToPx(sideMargin*node.getLevel() ), 0, 0, 0 );
        mItem.setLayoutParams(layoutParams);
        mItem.addView(view);
        ((LinearLayout)adapter.root.getView()).addView(mItem);
    }
}
 
Example 11
Project: MyCalendar   File: SubjectOfAdapter.java   Source Code and License Vote up 5 votes
private SubjectOfTeacherViewHolder(View itemView) {
    super(mContext, itemView);
    background = itemView.findViewById(R.id.subject_of_teacher_background);
    subject_name = itemView.findViewById(R.id.subject_name);
    subject_day = itemView.findViewById(R.id.subjects_date);
    itemView.setOnLongClickListener(null);
    popupMenu.setOnMenuItemClickListener(null);
}
 
Example 12
Project: Pocket-Plays-for-Twitch   File: MainActivityAdapter.java   Source Code and License Vote up 5 votes
@Override
// Is called every time a new viewHolder instance is created.
// It tells the adapter how we want to the layout of the data for each row should be formatted
public T onCreateViewHolder(ViewGroup viewGroup, int i) {
	View itemView = LayoutInflater.
			from(viewGroup.getContext()).
			inflate(getLayoutRessource(), viewGroup, false);

	itemView.setOnClickListener(mOnClickListener);
	itemView.setOnLongClickListener(mOnLongClickListener);
	return getElementsViewHolder(itemView);
}
 
Example 13
Project: labtablet   File: MetadataListAdapter.java   Source Code and License Vote up 5 votes
public MetadataListVH(View rowView) {
    super(rowView);
    mDescriptorName = (TextView) rowView.findViewById(R.id.metadata_item_title);
    mDescriptorType = (ImageView) rowView.findViewById(R.id.metadata_item_type);
    mDescriptorValue = (TextView) rowView.findViewById(R.id.metadata_item_value);
    mItemDeleteView = (LinearLayout) rowView.findViewById(R.id.item_metadata_list_expanded_view);

    rowView.setOnClickListener(this);
    rowView.setOnLongClickListener(this);
}
 
Example 14
Project: floating_calc   File: FloatingPageAdapter.java   Source Code and License Vote up 5 votes
private void applyListener(View view) {
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            applyListener(((ViewGroup) view).getChildAt(i));
        }
    } else if (view instanceof Button) {
        view.setOnClickListener(mOnClickListener);
        view.setOnLongClickListener(mOnLongClickListener);
    } else if (view instanceof ImageButton) {
        view.setOnClickListener(mOnClickListener);
        view.setOnLongClickListener(mOnLongClickListener);
    }
}
 
Example 15
Project: RLibrary   File: ViewHolder.java   Source Code and License Vote up 4 votes
public ViewHolder setOnLongClickListener(int viewId,
                                         View.OnLongClickListener listener) {
    View view = getView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
Example 16
Project: IslamicLibraryAndroid   File: BookListRecyclerViewAdapter.java   Source Code and License Vote up 4 votes
public ViewHolder(final View bookCover) {
    super(bookCover);
    bookCoverImageView = bookCover.findViewById(R.id.book_cover);
    bookCoverName = bookCover.findViewById(R.id.book_label);
    bookCoverAuthor = bookCover.findViewById(R.id.bookauthor);
    bookCheckBox = bookCover.findViewById(R.id.book_ceckBox);
    if (null != mListener) {
        bookCheckBox.setVisibility(mListener.isInSelectionMode() ? View.VISIBLE : View.GONE);
    }
    moreButton= bookCover.findViewById(R.id.book_overflow_btn);
    moreButton.setOnClickListener(v -> mListener.onMoreButtonClicked(bookInfo,v));

    bookCover.setOnClickListener(v -> mListener.OnBookTitleClick(bookInfo.getBookId(), bookInfo.getName()));
    bookCover.setOnLongClickListener(v -> {
        boolean handled = false;
        if (null != mListener) {
            // Notify the active callbacks interface (the activity, if the
            // fragment is attached to one) that an item has been lonClicked.
            handled = mListener.OnBookItemLongClicked(bookInfo.getBookId());
            bookCheckBox.setChecked(handled);
        }

        return handled;
    });

    bookCheckBox.setOnClickListener(v -> mListener.bookSelected(bookInfo.getBookId(), ((CheckBox) v).isChecked()));
    downloadButton = bookCover.findViewById(R.id.btn_download);
    downloadIndicator = bookCover.findViewById(R.id.download_indicator);
}
 
Example 17
Project: Android-Code-Demos   File: CustomPopupWindow.java   Source Code and License Vote up 4 votes
public void setOnLongClickListener(int viewId, View.OnLongClickListener listener) {
    View view = findView(viewId);
    view.setOnLongClickListener(listener);
}
 
Example 18
Project: JD-Test   File: BaseViewHolder.java   Source Code and License Vote up 3 votes
/**
 * Sets the on long click listener of the view.
 *
 * @param viewId   The view id.
 * @param listener The on long click listener;
 * @return The BaseViewHolder for chaining.
 * Please use {@link #addOnLongClickListener(int)} (adapter.setOnItemChildLongClickListener(listener))}
 */
@Deprecated
public BaseViewHolder setOnLongClickListener(int viewId, View.OnLongClickListener listener) {
    View view = getView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
Example 19
Project: Messenger-Android-XML-Template   File: ContactAdapter.java   Source Code and License Vote up 3 votes
public ViewHolder(View itemLayoutView,ContactAdapter.ViewHolder.ClickListener listener) {
    super(itemLayoutView);

    this.listener = listener;

    tvName = (TextView) itemLayoutView.findViewById(R.id.tv_user_name);
    userPhoto = (ImageView) itemLayoutView.findViewById(R.id.iv_user_photo);

    itemLayoutView.setOnClickListener(this);

    itemLayoutView.setOnLongClickListener (this);
}
 
Example 20
Project: AndFast   File: BaseViewHolder.java   Source Code and License Vote up 2 votes
/**
 * Sets the on long click listener of the view.
 *
 * @param viewId   The view id.
 * @param listener The on long click listener;
 * @return The BaseViewHolder for chaining.
 */
public BaseViewHolder setOnLongClickListener(int viewId, View.OnLongClickListener listener) {
    View view = getView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}