当前位置: 首页>>代码示例>>Java>>正文


Java View.setOnLongClickListener方法代码示例

本文整理汇总了Java中android.view.View.setOnLongClickListener方法的典型用法代码示例。如果您正苦于以下问题:Java View.setOnLongClickListener方法的具体用法?Java View.setOnLongClickListener怎么用?Java View.setOnLongClickListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.View的用法示例。


在下文中一共展示了View.setOnLongClickListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreateViewHolder

import android.view.View; //导入方法依赖的package包/类
/**
 * 创建一个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;
}
 
开发者ID:FZZFVII,项目名称:pipe,代码行数:31,代码来源:RecyclerAdapter.java

示例2: initItemClickListener

import android.view.View; //导入方法依赖的package包/类
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);
            }
        });
    }
}
 
开发者ID:bigjelly,项目名称:AndFast,代码行数:19,代码来源:BaseRecyclerAdapter.java

示例3: addOnLongClickListener

import android.view.View; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:BaseViewHolder.java

示例4: onCreateViewHolder

import android.view.View; //导入方法依赖的package包/类
@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;
}
 
开发者ID:henrymorgen,项目名称:android-advanced-light,代码行数:12,代码来源:HomeAdapter.java

示例5: BaseViewHolder

import android.view.View; //导入方法依赖的package包/类
public BaseViewHolder(View itemView) {
    super(itemView);
    this.mItemView = itemView;
    itemView.setOnClickListener(this);
    itemView.setOnLongClickListener(this);
    viewSparseArray = new SparseArray<>();
}
 
开发者ID:yangchong211,项目名称:YCBaseAdapter,代码行数:8,代码来源:BaseViewHolder.java

示例6: createTreeItem

import android.view.View; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:jakebonk,项目名称:DraggableTreeView,代码行数:36,代码来源:DraggableTreeView.java

示例7: setOnLongClickListener

import android.view.View; //导入方法依赖的package包/类
public ViewHolder setOnLongClickListener(int viewId,
                                         View.OnLongClickListener listener)
{
    View view = getView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
开发者ID:lanyan520,项目名称:Idea-ChainSelector,代码行数:8,代码来源:ViewHolder.java

示例8: DataListVH

import android.view.View; //导入方法依赖的package包/类
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);
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:14,代码来源:DataListAdapter.java

示例9: onCreate

import android.view.View; //导入方法依赖的package包/类
/**
 * 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");
}
 
开发者ID:RightMesh,项目名称:Ripple,代码行数:40,代码来源:MainActivity.java

示例10: SubjectOfTeacherViewHolder

import android.view.View; //导入方法依赖的package包/类
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);
}
 
开发者ID:nhocga1995s,项目名称:MyCalendar,代码行数:9,代码来源:SubjectOfAdapter.java

示例11: onCreateViewHolder

import android.view.View; //导入方法依赖的package包/类
@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);
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:13,代码来源:MainActivityAdapter.java

示例12: MetadataListVH

import android.view.View; //导入方法依赖的package包/类
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);
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:11,代码来源:MetadataListAdapter.java

示例13: applyListener

import android.view.View; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:tranleduy2000,项目名称:floating_calc,代码行数:14,代码来源:FloatingPageAdapter.java

示例14: setOnLongClickListener

import android.view.View; //导入方法依赖的package包/类
public ViewHolder setOnLongClickListener(int viewId,
                                         View.OnLongClickListener listener) {
    View view = getView(viewId);
    view.setOnLongClickListener(listener);
    return this;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:7,代码来源:ViewHolder.java

示例15: ViewHolder

import android.view.View; //导入方法依赖的package包/类
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);
}
 
开发者ID:fekracomputers,项目名称:IslamicLibraryAndroid,代码行数:30,代码来源:BookListRecyclerViewAdapter.java


注:本文中的android.view.View.setOnLongClickListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。