Java Code Examples for android.view.View#setOnClickListener()
The following examples show how to use
android.view.View#setOnClickListener() .
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: SettingsFragment.java From JPPF with Apache License 2.0 | 8 votes |
/** * Sets up the action bar for an {@link PreferenceScreen}. * @param preferenceScreen the preference screen on which to set the action bar. */ private static void initializeActionBar(PreferenceScreen preferenceScreen) { final Dialog dialog = preferenceScreen.getDialog(); if (dialog != null) { dialog.getActionBar().setDisplayHomeAsUpEnabled(true); View homeBtn = dialog.findViewById(android.R.id.home); if (homeBtn != null) { View.OnClickListener dismissDialogClickListener = new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }; ViewParent homeBtnContainer = homeBtn.getParent(); if (homeBtnContainer instanceof FrameLayout) { ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent(); if (containerParent instanceof LinearLayout) containerParent.setOnClickListener(dismissDialogClickListener); else ((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener); } else homeBtn.setOnClickListener(dismissDialogClickListener); } } }
Example 2
Source File: QuestionRecycleViewAdapter.java From nono-android with GNU General Public License v3.0 | 6 votes |
public NormalViewHolder(View convertview,QuestionItemClickListener clickListener,QuestionItemLongClickListener longClickListener) { super(convertview); this.clickListener =clickListener; this.longClickListener = longClickListener; this.titleTextView=(TextView)convertview.findViewById(R.id.question_title); this.questionRaiseTimeTextView = (TextView)convertview.findViewById(R.id.question_raise_time); this.questionRaiseNameView = (TextView)convertview.findViewById(R.id.question_raiser); this.questionAnswerNumView = (TextView)convertview.findViewById(R.id.question_answer_num); this.questionHotDegreeView = (TextView)convertview.findViewById(R.id.question_hot_degree); this.questionAbstractView = (TextView)convertview.findViewById(R.id.question_abstract); this.questionRaiserHeadImage = (SimpleDraweeView)convertview.findViewById(R.id.question_raiser_headimage); this.questionOfficalState = (ImageView)convertview.findViewById(R.id.question_offical_state); convertview.setOnClickListener(this); convertview.setOnLongClickListener(this); }
Example 3
Source File: DeleteActionFragment.java From FloatingView with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_delete_action, container, false); // 削除ボタン final View clearFloatingButton = rootView.findViewById(R.id.clearDemo); clearFloatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Easy way to delete a service final Activity activity = getActivity(); activity.stopService(new Intent(activity, CustomFloatingViewService.class)); } }); return rootView; }
Example 4
Source File: AccessLogActivity.java From DeviceConnect-Android with MIT License | 6 votes |
/** * コンストラクタ. * @param itemView RecyclerViewのルートView */ ViewHolder(View itemView) { super(itemView); mTextView = itemView.findViewById(R.id.accesslog_date_name); itemView.setOnClickListener((v) -> { if (mOnItemClickListener != null) { v.postDelayed(() -> mOnItemClickListener.onItemClick(itemView, getAdapterPosition()), 300); } }); // 画面がタッチされた時に Snackbar を非表示にする itemView.setOnTouchListener((v, event) -> { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: dismissSnackbar(); break; } return false; }); }
Example 5
Source File: WhatIfFragment.java From Easy_xkcd with Apache License 2.0 | 5 votes |
@Override public ComicViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.whatif_overview, viewGroup, false); v.setOnClickListener(new CustomOnClickListener()); v.setOnLongClickListener(new CustomOnLongClickListener()); return new ComicViewHolder(v); }
Example 6
Source File: DeploymentsRecyclerAdapter.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 5 votes |
public DeploymentsViewHolder(View itemView) { super(itemView); nameTextView = (TextView)itemView.findViewById(R.id.name); descriptionTextView = (TextView)itemView.findViewById(R.id.description); itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent deploymentDetailsActivity = new Intent(context, DeploymentDetailsActivity.class); deploymentDetailsActivity.putExtra("POSITION", getLayoutPosition()); context.startActivity(deploymentDetailsActivity); } }); }
Example 7
Source File: IMBaseLoginActivity.java From imsdk-android with MIT License | 5 votes |
protected void bindCheckUpdateView(View v){ if(v == null) return; v.setOnClickListener((view) -> { clickCount++; if(clickCount >= 6){ goAbout(); clickCount = 0; } }); }
Example 8
Source File: ClickGuardTest.java From clickguard with Apache License 2.0 | 5 votes |
private void clickViews(View... views) { for (View view : views) { view.performClick(); view.setOnClickListener(new ClickGuard.GuardedOnClickListener() { @Override public boolean onClicked() { return true; } }); } }
Example 9
Source File: MenuBadgeUtils.java From AccountBook with GNU General Public License v3.0 | 5 votes |
/** * 更新消息数量,当 0 时隐藏. * @param act 菜单对应 Activity * @param menu 菜单 item * @param resId 菜单图片 * @param count 消息数量 */ public static void update(final Activity act, final MenuItem menu, int resId, int count){ if(menu == null) return; View badge = menu.getActionView(); if(badge == null){ menu.setActionView(R.layout.menu_action_item_badge); badge = menu.getActionView(); } ImageView imgBadge = (ImageView) badge.findViewById(R.id.menu_badge_icon); TextView txtBadge = (TextView) badge.findViewById(R.id.menu_badge); if(resId != -1){ imgBadge.setImageResource(resId); } if(count > 0){ txtBadge.setVisibility(View.VISIBLE); if(count < 10){ txtBadge.setTextSize(12f); txtBadge.setText(String.valueOf(count)); }else{ txtBadge.setTextSize(10f); txtBadge.setText("9+"); } }else{ txtBadge.setVisibility(View.GONE); } badge.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { act.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, menu); } }); }
Example 10
Source File: BlogAdapter.java From KJFrameForAndroid with Apache License 2.0 | 5 votes |
private void onPicClick(View view, final String url) { view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { UIHelper.toGallery(v.getContext(), url); } }); }
Example 11
Source File: NgClick.java From ngAndroid with Apache License 2.0 | 5 votes |
public void attach(Scope scope, View view, int layoutId, int viewId, int attr, boolean isLongClick){ Executor executor = new Executor(scope, layoutId, viewId, attr); if(!isLongClick) view.setOnClickListener(executor); else view.setOnLongClickListener(executor); }
Example 12
Source File: BaseThreadAndArticleAdapter.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
public View getOneImageAdItem(int position, View convertView) { if (convertView == null) { convertView = LayoutInflater.from(context).inflate( R.layout.item_forum_ad_image, null); } ImageView image1 = ViewHolder.get(convertView, R.id.image1); ImageView iconImage = ViewHolder.get(convertView, R.id.icon); TextView nameText = ViewHolder.get(convertView, R.id.name); TextView dateText = ViewHolder.get(convertView, R.id.date); TextView viewText = ViewHolder.get(convertView, R.id.view); TextView replyText = ViewHolder.get(convertView, R.id.reply); TextView content = ViewHolder.get(convertView, R.id.content_title); final ForumAdJson forumAd = (ForumAdJson) getItem(position); nameText.setTextColor(ThemeUtils.getThemeColor(context)); nameText.setText(StringUtils.get(forumAd.getName())); dateText.setText(ClanUtils.computeThreadTime(forumAd.getTime())); viewText.setVisibility(View.GONE); replyText.setVisibility(View.GONE); setColoredAdContent(content, forumAd); final String[] urls = forumAd.getImages(); LoadImageUtils.displayAvatar(context, iconImage, StringUtils.get(forumAd.getIcon())); LoadImageUtils.display(context, image1, urls[0]); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { clickAd(forumAd); } }); return convertView; }
Example 13
Source File: ContributorView.java From KernelAdiutor with GNU General Public License v3.0 | 5 votes |
@Override public void onCreateView(View view) { super.onCreateView(view); CircularImageView image = view.findViewById(R.id.image); TextView name = view.findViewById(R.id.name); TextView contributions = view.findViewById(R.id.contributions); ViewUtils.loadImagefromUrl(mContributor.getAvatarUrl(), image); name.setText(mContributor.getLogin()); contributions.setText(view.getResources().getString(R.string.commits, mContributor.getContributions())); view.setOnClickListener(v -> Utils.launchUrl(mContributor.getHtmlUrl(), v.getContext())); }
Example 14
Source File: PropertiesAdapter.java From android-periodic-table with GNU General Public License v3.0 | 5 votes |
public ViewHolder(View itemView) { super(itemView); mName = (TextView) itemView.findViewById(R.id.property_name); mValue = (TextView) itemView.findViewById(R.id.property_value); if (mValue != null) { mValue.setTypeface(mTypeface); itemView.setOnClickListener(this); itemView.setOnCreateContextMenuListener(this); } }
Example 15
Source File: BaseThreadAndArticleAdapter.java From BigApp_Discuz_Android with Apache License 2.0 | 4 votes |
/** * 带图片的主题 * * @param position * @param convertView * @return */ public View getItemWithImages(int position, View convertView) { if (convertView == null) { convertView = LayoutInflater.from(context).inflate( R.layout.item_forum_thread_image, null); } ImageView image1 = ViewHolder.get(convertView, R.id.image1); ImageView image2 = ViewHolder.get(convertView, R.id.image2); ImageView image3 = ViewHolder.get(convertView, R.id.image3); ImageView iconImage = ViewHolder.get(convertView, R.id.icon); TextView nameText = ViewHolder.get(convertView, R.id.name); TextView dateText = ViewHolder.get(convertView, R.id.date); TextView viewText = ViewHolder.get(convertView, R.id.view); TextView replyText = ViewHolder.get(convertView, R.id.reply); TextView content = ViewHolder.get(convertView, R.id.content); TextView imageNumText = ViewHolder.get(convertView, R.id.image_num); View rlImageNum = ViewHolder.get(convertView, R.id.rlImageNum); ImageView tag1 = ViewHolder.get(convertView, R.id.tag1); ImageView tag2 = ViewHolder.get(convertView, R.id.tag2); ImageView tag3 = ViewHolder.get(convertView, R.id.tag3); TextView contentTitleText = ViewHolder.get(convertView, R.id.content_title); TextView tvForumName = ViewHolder.get(convertView, R.id.tvForumName); final Thread thread = (Thread) getItem(position); nameText.setTextColor(ThemeUtils.getThemeColor(context)); nameText.setText(StringUtils.get(thread.getAuthor())); dateText.setText(StringUtils.get(thread.getDateline())); viewText.setText(context.getString(R.string.text_num_view, StringUtils.get(thread.getViews()))); replyText.setText(context.getString(R.string.text_num_reply, StringUtils.get(thread.getReplies()))); final ArrayList<String> urls = thread.getAttachmentUrls(); final int size = urls.size(); imageNumText.setVisibility(size >= 3 ? View.VISIBLE : View.GONE); imageNumText.setText(context.getString(R.string.image_count, size)); ContentUtils.setContent(context, content, thread.getMessageAbstract(), context.getResources().getColor(R.color.text_black_content), context.getResources().getColor(R.color.text_black_selected)); ZogUtils.printError(BaseThreadAndArticleAdapter.class, "images avatar:" + thread.getAvatar()); LoadImageUtils.displayAvatar(context, iconImage, thread.getAvatar()); LoadImageUtils.display(context, image1, urls.get(0)); image2.setVisibility(size >= 2 ? View.VISIBLE : View.GONE); image3.setVisibility(size >= 3 ? View.VISIBLE : View.GONE); rlImageNum.setVisibility(size >= 3 ? View.VISIBLE : View.GONE); if (size > 1) { LoadImageUtils.display(context, image2, urls.get(1)); if (size > 2) { LoadImageUtils.display(context, image3, urls.get(2)); } } ContentUtils.setColoredContent(context, mForum, contentTitleText, nameText, thread, isShowType(), isTypeClickable()); ThreadAndArticleItemUtils.setForumName(context, thread, tvForumName); ThreadAndArticleItemUtils.showTags(thread, tag1, tag2, tag3); convertView.setOnClickListener(new ForumClickListener(context, thread.getTid())); return convertView; }
Example 16
Source File: GeoARActivity.java From geoar-app with Apache License 2.0 | 4 votes |
@Override public View onCreateActionView() { // Inflate the action view to be shown on the action bar. actionView = mInflater.inflate(R.layout.datasource_list_actionitem, null); // TODO use ActionMenuItemView when ABS resources work // actionView.findViewById(R.id.button).setOnClickListener( // new OnClickListener() { // @Override // public void onClick(View v) { // if (getPopup().isShowing()) { // mPopup.dismiss(); // } else { // // Offset by top margin to align top // mPopup.showAsDropDown(actionView, 0, -mPopup // .getContentView().getPaddingTop()); // } // } // }); final View view = actionView.findViewById(R.id.button); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (getPopup().isShowing()) { mPopup.dismiss(); } else { // Offset by top margin to align top mPopup.showAsDropDown(actionView, 0, -mPopup .getContentView().getPaddingTop()); IntroController.notify(getPopup().getContentView() .findViewById(R.id.buttonMore)); IntroController.notify(R.string.intro_desc_3_3); } } }); IntroController.addViewToStep(1, view); IntroController.addViewToStep(2, getPopup().getContentView() .findViewById(R.id.buttonMore)); IntroController.addViewToStep(8, view); IntroController.notify(view); return actionView; }
Example 17
Source File: BaseActivity.java From FamilyChat with Apache License 2.0 | 4 votes |
/** * 添加点击监听到onClick()中 */ protected void addClick(View view) { if (view != null) view.setOnClickListener(this); }
Example 18
Source File: ForumListAdapter.java From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 | 4 votes |
@Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = mLayoutInflater.inflate(R.layout.list_board_icon, parent, false); view.setOnClickListener(mListener); return new ViewHolder(view); }
Example 19
Source File: ColorSelectionRecyclerViewAdapter.java From wear-os-samples with Apache License 2.0 | 4 votes |
public ColorViewHolder(final View view) { super(view); mColorCircleImageView = (CircledImageView) view.findViewById(R.id.color); view.setOnClickListener(this); }
Example 20
Source File: BaseAdapterHelper.java From AndroidBase with Apache License 2.0 | 2 votes |
/** * Sets the on click listener of the view. * * @param viewId * The view id. * @param listener * The on click listener; * @return The BaseAdapterHelper for chaining. */ public BaseAdapterHelper setOnClickListener(int viewId, View.OnClickListener listener) { View view = retrieveView(viewId); view.setOnClickListener(listener); return this; }