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

The following examples show how to use android.view.View#setOnLongClickListener() . These examples are extracted from open source projects. 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 Project: demo4Fish   File: BaseViewHolder.java    License: MIT License 6 votes vote down vote up
/**
 * 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
 */
public BaseViewHolder addOnLongClickListener(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) {
                if (adapter.getmOnItemChildLongClickListener() != null) {
                    return adapter.getmOnItemChildLongClickListener().onItemChildLongClick(adapter, v, getClickPosition());
                }
                return false;
            }
        });
    }
    return this;
}
 
Example 2
Source Project: Musync   File: AlbumSongAdapter.java    License: MIT License 6 votes vote down vote up
public MyViewHolder(View view) {
    super(view);
    SongName = (TextView) view.findViewById(R.id.songName);
    SongPostion = (TextView) view.findViewById(R.id.postionTV);
    artistName = (TextView) view.findViewById(R.id.artistName);
    musicIndicator = (Indicator) view.findViewById(R.id.MusicIndicator);
    songLL = (LinearLayout) view.findViewById(R.id.songLL);
    totatSongsTV = (TextView) view.findViewById(R.id.totalSongsTextView);

    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {

            int pos = getLayoutPosition();

            return true;
        }
    });
}
 
Example 3
/**
 * To bind different types of holder and solve different the bind events
 *
 * @param holder
 * @param positions
 * @see #getDefItemViewType(int)
 */
@Override
public void onBindViewHolder(K holder, int positions) {
    super.onBindViewHolder(holder, positions);
    int viewType = holder.getItemViewType();

    if (mItemTouchHelper != null && itemDragEnabled && viewType != LOADING_VIEW && viewType != HEADER_VIEW
            && viewType != EMPTY_VIEW && viewType != FOOTER_VIEW) {
        if (mToggleViewId != NO_TOGGLE_VIEW) {
            View toggleView = ((BaseViewHolder) holder).getView(mToggleViewId);
            if (toggleView != null) {
                toggleView.setTag(R.id.BaseQuickAdapter_viewholder_support, holder);
                if (mDragOnLongPress) {
                    toggleView.setOnLongClickListener(mOnToggleViewLongClickListener);
                } else {
                    toggleView.setOnTouchListener(mOnToggleViewTouchListener);
                }
            }
        } else {
            holder.itemView.setTag(R.id.BaseQuickAdapter_viewholder_support, holder);
            holder.itemView.setOnLongClickListener(mOnToggleViewLongClickListener);
        }
    }
}
 
Example 4
@Override
public EmoteViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
	View itemView = LayoutInflater
			.from(parent.getContext())
			.inflate(R.layout.view_emote_showcase, parent, false);

	itemView.setOnClickListener(emoteClickListener);
	itemView.setOnLongClickListener(emoteLongClickListener);
	return new EmoteViewHolder(itemView);
}
 
Example 5
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
	final View view = mInflater.inflate(mLayoutId, parent, false);
	view.setOnClickListener(mOnClickListener);
	view.setOnLongClickListener(mOnLongClickListener);
	return new ViewHolder(view);
}
 
Example 6
@Override
public void onChildViewAttachedToWindow(View view) {
    if (mOnItemClickListener != null) {
        view.setOnClickListener(mOnClickListener);
    }
    if (mOnItemLongClickListener != null) {
        view.setOnLongClickListener(mOnLongClickListener);
    }
}
 
Example 7
private void addDetailsItem(String title, String info) {
	View v = View.inflate(
			new ContextThemeWrapper(
					getApplicationContext(),
					R.style.Base_Theme_AppCompat_Light
			), R.layout.simple_list_item, null
	);

	((TextView) v.findViewById(android.R.id.text1)).setText(title);
	((TextView) v.findViewById(android.R.id.text2)).setText(info);
	v.setTag(title + ": " + info);
	v.setOnLongClickListener(new View.OnLongClickListener() {
		@Override
		public boolean onLongClick(View view) {
			setClipboard((String) view.getTag());
			Toast.makeText(
					getApplicationContext(),
					R.string.details_has_copied,
					Toast.LENGTH_SHORT
			).show();
			return true;
		}
	});

	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

	mContentLayout.addView(v, 0, lp);
}
 
Example 8
Holder(View itemView) {
    super(itemView);
    preview = itemView.findViewById(R.id.preview);
    selection = itemView.findViewById(R.id.selection);
    isVideo = itemView.findViewById(R.id.isVideo);
    itemView.setOnClickListener(this);
    itemView.setOnLongClickListener(this);
}
 
Example 9
Source Project: stitch-android-sdk   File: TodoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
TodoItemViewHolder(final View view) {
  super(view);
  taskTextView = view.findViewById(R.id.tv_task);
  taskCheckbox = view.findViewById(R.id.cb_todo_checkbox);

  // Set listeners
  taskCheckbox.setOnCheckedChangeListener(this);
  view.setOnClickListener(this);
  view.setOnLongClickListener(this);
  taskCheckbox.setOnClickListener(this);
  taskCheckbox.setOnLongClickListener(this);
}
 
Example 10
ViewHolder(View itemView) {
    super(itemView);
    bodyView = (TextView) itemView.findViewById(R.id.body);
    typeView = (TextView) itemView.findViewById(R.id.type);
    titleView = (TextView) itemView.findViewById(R.id.title);
    descView = (TextView) itemView.findViewById(R.id.desc);
    timestampView = (TextView) itemView.findViewById(R.id.timestamp);
    line = itemView.findViewById(R.id.line);

    itemView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (mCurMessage != null) {
                try {
                    if (mCurMessage.type != null && mCurMessage.type.equalsIgnoreCase(NetworkEventSender.TYPE_REQUEST)) {
                        if (!TextUtils.isEmpty(mCurMessage.title)) {
                            SDKUtils.copyToClipboard(v.getContext(), mCurMessage.title, true);
                        }
                    } else if (mCurMessage.type != null && mCurMessage.type.equalsIgnoreCase(NetworkEventSender.TYPE_RESPONSE)) {
                        if (!TextUtils.isEmpty(mCurMessage.body)) {
                            SDKUtils.copyToClipboard(v.getContext(), mCurMessage.body, true);
                        }
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return true;
        }
    });
}
 
Example 11
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v;
    RecyclerView.ViewHolder viewHolder;

    int resource = R.layout.fragment_weapon_tree_item_bowgun;
    v = LayoutInflater.from(parent.getContext())
            .inflate(resource, parent, false);

    viewHolder = new WeaponBowgunViewHolder(v);

    v.setOnLongClickListener(mListener);

    return viewHolder;
}
 
Example 12
@NonNull
@Override
   public ViewHolder<T> onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
	final LayoutInflater inflater = getLayoutInflater(parent.getContext());
       final View view = onCreateItemView(inflater, parent, viewType);
	view.setOnClickListener(mOnClickListener);
	view.setOnLongClickListener(mOnLongClickListener);
       return onCreateViewHolder(view);
   }
 
Example 13
Source Project: DevUtils   File: ListenerUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置长按事件
 * @param activity            {@link Activity}
 * @param onLongClickListener {@link View.OnLongClickListener}
 * @param viewIds             View id 数组
 * @return {@code true} success, {@code false} fail
 */
public static boolean setOnLongClicks(final Activity activity, final View.OnLongClickListener onLongClickListener, @IdRes final int... viewIds) {
    if (activity != null && onLongClickListener != null && viewIds != null) {
        for (int i = 0, len = viewIds.length; i < len; i++) {
            View findView = ViewUtils.findViewById(activity, viewIds[i]);
            if (findView != null) {
                findView.setOnLongClickListener(onLongClickListener);
            }
        }
        return true;
    }
    return false;
}
 
Example 14
public MediaEntryViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);

    itemView.setOnClickListener(this);
    itemView.setOnLongClickListener(this);
}
 
Example 15
void bindView(View view, final Context context, final Calibration calibration) {
    final CalibrationDataCursorAdapterViewHolder tag = (CalibrationDataCursorAdapterViewHolder) view.getTag();
    tag.raw_data_id.setText(JoH.qs(calibration.bg, 4) + "    "+ BgGraphBuilder.unitized_string_static(calibration.bg));
    tag.raw_data_value.setText("raw: " + JoH.qs(calibration.estimate_raw_at_time_of_calibration, 4));
    tag.raw_data_slope.setText("slope: " + JoH.qs(calibration.slope, 4) + " intercept: " + JoH.qs(calibration.intercept, 4));
    tag.raw_data_timestamp.setText(JoH.dateTimeText(calibration.timestamp) + "  (" + JoH.dateTimeText(calibration.raw_timestamp) + ")");

    if (calibration.isNote()) {
        // green note
        view.setBackgroundColor(Color.parseColor("#004400"));
    } else if (!calibration.isValid()) {
        // red invalid/cancelled/overridden
        view.setBackgroundColor(Color.parseColor("#660000"));
    } else {
        // normal grey
        view.setBackgroundColor(Color.parseColor("#212121"));
    }

    view.setLongClickable(true);
    view.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    switch (which){
                        case DialogInterface.BUTTON_POSITIVE:
                            calibration.clear_byuuid(calibration.uuid, false);
                            notifyDataSetChanged();
                            break;

                        case DialogInterface.BUTTON_NEGATIVE:
                            break;
                    }
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage("Disable this calibration?\nFlagged calibrations will no longer have an effect.").setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();
            return true;
        }
    });


}
 
Example 16
Source Project: fogger   File: ActivityWithContextMenu.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void unregisterForContextMenu(View view) {
    super.unregisterForContextMenu(view);
    view.setOnLongClickListener(null);
}
 
Example 17
/**
 * Sets the on long click listener of the view.
 *
 * @param viewId   The view id.
 * @param listener The on long click listener;
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setOnLongClickListener(int viewId,
                                                View.OnLongClickListener listener) {
    View view = retrieveView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
Example 18
/**
 * Sets the on long click listener of the view.
 *
 * @param viewId   The view id.
 * @param listener The on long click listener;
 * @return The BaseAdapterHelper for chaining.
 */
public BaseAdapterHelper setOnLongClickListener(int viewId,
                                                View.OnLongClickListener listener) {
    View view = retrieveView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
Example 19
Source Project: basic-adapter   File: BaseViewHolder.java    License: MIT License 2 votes vote down vote up
/**
 * Sets the on longClick listener of the view.
 * @param viewId
 * @param listener
 * @return
 */
public BaseViewHolder setOnLongClickListener(int viewId, OnLongClickListener listener) {
    View view = getView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
Example 20
Source Project: material-intro   File: CheatSheet.java    License: MIT License 2 votes vote down vote up
/**
 * Removes the cheat sheet for the given view by removing the view's {@link
 * android.view.View.OnLongClickListener}.
 *
 * @param view The view whose cheat sheet should be removed.
 */
public static void remove(final View view) {
    view.setOnLongClickListener(null);
}