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

The following are Jave code examples for showing how to use setOnClickListener() 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: home-automation   File: MainActivity.java   Source Code and License Vote up 7 votes
/**
 * Initialize the drawer.
 */
private void setupDrawerLayout() {
    drawerLayout = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    View header = navigationView.getHeaderView(0);
    header.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            drawerLayout.closeDrawers();
        }
    });

    final Toolbar toolbar = findViewById(R.id.toolbar);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
            this,  drawerLayout, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close
    );
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
    actionBarDrawerToggle.syncState();
}
 
Example 2
Project: Hotspot-master-devp   File: AdapterWrapper.java   Source Code and License Vote up 6 votes
/**
 * Get a header view. This optionally pulls a header from the supplied
 * {@link WrapperView} and will also recycle the divider if it exists.
 */
private View configureHeader(WrapperView wv, final int position) {
	View header = wv.mHeader == null ? popHeader() : wv.mHeader;
	header = mDelegate.getHeaderView(position, header, wv);
	if (header == null) {
		throw new NullPointerException("Header view must not be null.");
	}
	//if the header isn't clickable, the listselector will be drawn on top of the header
	header.setClickable(true);
	header.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {
			if(mOnHeaderClickListener != null){
				long headerId = mDelegate.getHeaderId(position);
				mOnHeaderClickListener.onHeaderClick(v, position, headerId);
			}
		}
	});
	return header;
}
 
Example 3
Project: Blockly   File: FlyoutController.java   Source Code and License Vote up 5 votes
/**
 * @param trashIcon The view for toggling the trash.
 */
public void setTrashIcon(View trashIcon) {
    if (trashIcon == null) {
        return;
    }
    // The trash icon is always a drop target.
    trashIcon.setOnDragListener(new OnDragToTrashListener(mController));
    if (mTrashUi != null && mTrashIsCloseable) {
        // But we only need a click listener if the trash can be closed.
        trashIcon.setOnClickListener(mTrashClickListener);
    }
}
 
Example 4
Project: Auto.js   File: DrawerMenuItemViewHolder.java   Source Code and License Vote up 5 votes
public DrawerMenuItemViewHolder(View itemView) {
    super(itemView);
    ButterKnife.bind(this, itemView);
    mSwitchCompat.setOnCheckedChangeListener((buttonView, isChecked) -> onClick());
    itemView.setOnClickListener(v -> {
        if (mSwitchCompat.getVisibility() == VISIBLE) {
            mSwitchCompat.toggle();
        } else {
            onClick();
        }
    });
}
 
Example 5
Project: revolution-irc   File: NotificationRulesAdapter.java   Source Code and License Vote up 5 votes
public UserRuleHolder(NotificationRulesAdapter adapter, View itemView) {
    super(adapter, itemView);
    itemView.setOnClickListener((View view) -> {
        Intent intent = new Intent(view.getContext(), EditNotificationSettingsActivity.class);
        intent.putExtra(EditNotificationSettingsActivity.ARG_USER_RULE_INDEX, getAdapterPosition() - adapter.getUserRulesStartIndex());
        view.getContext().startActivity(intent);
    });
    itemView.findViewById(R.id.reorder).setOnTouchListener((View v, MotionEvent e) -> {
        if (e.getActionMasked() == MotionEvent.ACTION_DOWN)
            adapter.mItemTouchHelper.startDrag(UserRuleHolder.this);
        return false;
    });
}
 
Example 6
Project: Pindroid   File: ItemAdapter.java   Source Code and License Vote up 5 votes
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycler_item, null);
    ItemHolder itemHolder = new ItemHolder(view);
    view.setOnClickListener(this);
    return itemHolder;
}
 
Example 7
Project: Hello-Music-droid   File: BaseQueueAdapter.java   Source Code and License Vote up 5 votes
public ItemHolder(View view) {
    super(view);
    this.title = (TextView) view.findViewById(R.id.song_title);
    this.artist = (TextView) view.findViewById(R.id.song_artist);
    this.albumArt = (ImageView) view.findViewById(R.id.albumArt);
    this.popupMenu = (ImageView) view.findViewById(R.id.popup_menu);
    visualizer = (MusicVisualizer) view.findViewById(R.id.visualizer);
    view.setOnClickListener(this);
}
 
Example 8
Project: AndroidUiKit   File: LoadMoreItemViewBinder.java   Source Code and License Vote up 5 votes
public ViewHolder(View itemView) {
    super(itemView);
    progressBar = (ProgressBar) itemView.findViewById(R.id.pb_loading);
    tips = (TextView) itemView.findViewById(R.id.tv_tips);
    itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (data.getState() == LoadMoreItem.STATE_FAILED && mRetryListener != null) {
                mRetryListener.onRetry();
                data.setState(LoadMoreItem.STATE_LOADING);
                updateView(LoadMoreItem.STATE_LOADING);
            }
        }
    });
}
 
Example 9
Project: easyfilemanager   File: ConnectionsAdapter.java   Source Code and License Vote up 5 votes
private View getDocumentView(int position, View convertView, ViewGroup parent) {
    final Context context = parent.getContext();

    if (convertView == null) {
        final LayoutInflater inflater = LayoutInflater.from(context);
        convertView = inflater.inflate(R.layout.item_connection_list, parent, false);
    }

    final Cursor cursor = getItem(position);

    NetworkConnection networkConnection = NetworkConnection.fromConnectionsCursor(cursor);

    final ImageView iconMime = (ImageView) convertView.findViewById(R.id.icon_mime);
    final View iconMimeBackground = convertView.findViewById(R.id.icon_mime_background);
    final TextView title = (TextView) convertView.findViewById(android.R.id.title);
    final ImageView icon1 = (ImageView) convertView.findViewById(android.R.id.icon1);
    final TextView summary = (TextView) convertView.findViewById(android.R.id.summary);
    final View popupButton = convertView.findViewById(R.id.button_popup);
    popupButton.setVisibility(isTelevision() ? View.INVISIBLE : View.VISIBLE);

    popupButton.setOnClickListener(mListener);
    title.setText(networkConnection.getName());
    summary.setText(networkConnection.getSummary());

    iconMimeBackground.setVisibility(View.VISIBLE);
    iconMimeBackground.setBackgroundColor(
            IconColorUtils.loadSchmeColor(context, networkConnection.getType()));
    iconMime.setImageDrawable(IconUtils.loadSchemeIcon(context, networkConnection.type));
            //ContextCompat.getDrawable(context, R.drawable.ic_connection_network));
    return convertView;
}
 
Example 10
Project: KrGallery   File: BaseDialog.java   Source Code and License Vote up 5 votes
public BaseDialog setBtnPanelView(int layoutId, OnClickListener listener) {
        ViewGroup viewGroup = (ViewGroup) getLayoutInflater().inflate(layoutId, null, false);
        int count = viewGroup.getChildCount();
        for (int i = 0; i < count; i++) {
            View child = viewGroup.getChildAt(i);
            if (child instanceof Button) {
                child.setOnClickListener(this);
            }
        }
        mListener = listener;
        mBtnPanel.addView(viewGroup);
//        设置容器的背景  可以根据实际情况动态添加
//        mContainer.setBackgroundResource(R.drawable.zhenai_library_dialog_base_top_shape);
        return this;
    }
 
Example 11
Project: yjPlay   File: VideoAdapter.java   Source Code and License Vote up 5 votes
public VideoViewHolder(View itemView) {
    super(itemView);
    playerView = (VideoPlayerView) itemView.findViewById(R.id.exo_play_context_id);
    userPlayer = new ManualPlayer((Activity) mContext, playerView);
    itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onItemClickListener.onItemClick(getAdapterPosition());
        }
    });
}
 
Example 12
Project: FriendBook   File: BaseActivity.java   Source Code and License Vote up 5 votes
public void bindOnClickLister(View rootView, View.OnClickListener listener, @IdRes int... ids) {
    for (int id : ids) {
        View view = rootView.findViewById(id);
        if (view != null) {
            view.setOnClickListener(listener);
        }
    }
}
 
Example 13
Project: Library-System-Android   File: PlaceHold.java   Source Code and License Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.placehold);

    View chooseButton = findViewById(R.id.choosedate_button);
    chooseButton.setOnClickListener(this);

    //Arrays for days to fill spinners
    ampm[0] = "AM";
    ampm[1] = "PM";
    Spinner daySpinner = (Spinner) findViewById(R.id.day_spinner);
    Spinner spinner = (Spinner) findViewById(R.id.month_spinner);

    for(int i=0;i<thirtyOneDays.length;i++){
        thirtyOneDays[i]=Integer.toString(1+i);
    }
    for(int i=0;i<twentyEightDays.length;i++){
        twentyEightDays[i]=Integer.toString(1+i);
    }
    for(int i=0;i<twentyNineDays.length;i++){
        twentyNineDays[i]=Integer.toString(1+i);
    }
    for(int i=0;i<thirtyDays.length;i++){
        thirtyDays[i]=Integer.toString(1+i);
    }
    for(int i=0;i<hours.length;i++){
        hours[i]=Integer.toString(1+i) + ":00";
    }

    //Month Spinner
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.month, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);
    String selected = spinner.getSelectedItem().toString();

    //System.out.println("selected: "+selected);
    spinner.setOnItemSelectedListener(this);

    //Day Spinner
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<String> dayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, thirtyOneDays);
    // Specify the layout to use when the list of choices appears
    dayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    daySpinner.setAdapter(dayAdapter);

    //Year Spinner
    Spinner yearSpinner = (Spinner) findViewById(R.id.year_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> yearAdapter = ArrayAdapter.createFromResource(this,
            R.array.years, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    yearAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    yearSpinner.setAdapter(yearAdapter);
    yearSpinner.setOnItemSelectedListener(this);

    //Hour Spinner
    Spinner hourSpinner = (Spinner) findViewById(R.id.hour_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<String> hourAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, hours);
    // Specify the layout to use when the list of choices appears
    hourAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    hourSpinner.setAdapter(hourAdapter);

    //ampm Spinner
    Spinner ampmSpinner = (Spinner) findViewById(R.id.ampm_spinner);
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<String> ampmAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ampm);
    // Specify the layout to use when the list of choices appears
    ampmAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    ampmSpinner.setAdapter(ampmAdapter);

}
 
Example 14
Project: android-dev-challenge   File: ForecastAdapter.java   Source Code and License Vote up 4 votes
public ForecastAdapterViewHolder(View view) {
    super(view);
    mWeatherTextView = (TextView) view.findViewById(R.id.tv_weather_data);
    // COMPLETED (7) Call setOnClickListener on the view passed into the constructor (use 'this' as the OnClickListener)
    view.setOnClickListener(this);
}
 
Example 15
Project: android_camera_experiment   File: PreviewActivity.java   Source Code and License Vote up 4 votes
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_preview);
        mContext = this;
        surfaceView = (SurfaceView) findViewById(R.id.video_preview);

        //隐藏掉Seekbar
//        surfaceView.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                if (mediaController == null) return false;
//                if (mediaController.isShowing()) {
//                    mediaController.hide();
//                    showButtonPanel(true);
//                } else {
//                    showButtonPanel(false);
//                    mediaController.show();
//                }
//                return false;
//            }
//        });

        videoPreviewContainer = (AspectFrameLayout) findViewById(R.id.previewAspectFrameLayout);
        photoPreviewContainer = (FrameLayout) findViewById(R.id.photo_preview_container);
        imagePreview = (UCropView) findViewById(R.id.image_view);
        buttonPanel = (ViewGroup) findViewById(R.id.preview_control_panel);
        View confirmMediaResult = findViewById(R.id.confirm_media_result);
        View reTakeMedia = findViewById(R.id.re_take_media);
        View cancelMediaAction = findViewById(R.id.cancel_media_action);

        findViewById(R.id.crop_image).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UCrop.Options options = new UCrop.Options();
                options.setToolbarColor(ContextCompat.getColor(mContext, android.R.color.black));
                options.setStatusBarColor(ContextCompat.getColor(mContext, android.R.color.black));
                Uri uri = Uri.fromFile(new File(previewFilePath));
                UCrop.of(uri, uri)
                        .withOptions(options)
                        .start(mContext);
            }
        });

        if (confirmMediaResult != null)
            confirmMediaResult.setOnClickListener(this);

        if (reTakeMedia != null)
            reTakeMedia.setOnClickListener(this);

        if (cancelMediaAction != null)
            cancelMediaAction.setOnClickListener(this);

        Bundle args = getIntent().getExtras();

        mediaAction = args.getInt(MEDIA_ACTION_ARG);
        previewFilePath = args.getString(FILE_PATH_ARG);
        showCrop = args.getBoolean(SHOW_CROP);

        if (mediaAction == CameraConfiguration.MEDIA_ACTION_VIDEO) {
            displayVideo(savedInstanceState);
        } else if (mediaAction == CameraConfiguration.MEDIA_ACTION_PHOTO) {
            displayImage();
        } else {
            String mimeType = Utils.getMimeType(previewFilePath);
            if (mimeType.contains(MIME_TYPE_VIDEO)) {
                displayVideo(savedInstanceState);
            } else if (mimeType.contains(MIME_TYPE_IMAGE)) {
                displayImage();
            } else finish();
        }
    }
 
Example 16
Project: HLOLI   File: HomeAdapter.java   Source Code and License Vote up 4 votes
public VideoHolder(View itemView) {

            super(itemView);
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
        }
 
Example 17
Project: KernelAdiutor-Mod   File: DropDownView.java   Source Code and License Vote up 4 votes
@Override
protected void refresh() {
    super.refresh();

    if (mTitle != null) {
        if (mTitleText != null) {
            mTitle.setText(mTitleText);
            mTitle.setVisibility(View.VISIBLE);
        } else {
            mTitle.setVisibility(View.GONE);
        }
    }
    if (mSummary != null) {
        if (mSummaryText != null) {
            mSummary.setText(mSummaryText);
            mSummary.setVisibility(View.VISIBLE);
        } else {
            mSummary.setVisibility(View.GONE);
        }
    }

    if (mParent != null && mItems != null) {
        mParent.removeAllViews();
        mDoneViews.clear();
        for (int i = 0; i < mItems.size(); i++) {
            View item = LayoutInflater.from(mParent.getContext()).inflate(R.layout.rv_drop_down_item_view,
                    mParent, false);
            ((TextView) item.findViewById(R.id.title)).setText(mItems.get(i));
            mDoneViews.add(item.findViewById(R.id.done_image));
            item.findViewById(R.id.done_image).setVisibility(View.GONE);

            final int position = i;
            item.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mSelection = position;
                    for (int i = 0; i < mDoneViews.size(); i++) {
                        mDoneViews.get(i).setVisibility(position == i ? View.VISIBLE : View.INVISIBLE);
                    }
                    if (mOnDropDownListener != null) {
                        mOnDropDownListener.onSelect(DropDownView.this, position, mItems.get(position));
                    }
                }
            });
            mParent.addView(item);
        }
        if (mSelection >= 0 && mSelection < mDoneViews.size()) {
            mDoneViews.get(mSelection).setVisibility(View.VISIBLE);
        }
    }
}
 
Example 18
Project: LaunchEnr   File: ShortcutsItemView.java   Source Code and License Vote up 4 votes
/**
 * Adds a {@link SystemShortcut.Widgets} item if there are widgets for the given ItemInfo.
 */
public void enableWidgetsIfExist(final BubbleTextView originalIcon) {
    ItemInfo itemInfo = (ItemInfo) originalIcon.getTag();
    SystemShortcut widgetInfo = new SystemShortcut.Widgets();
    View.OnClickListener onClickListener = widgetInfo.getOnClickListener(mLauncher, itemInfo);
    View widgetsView = null;
    for (View systemShortcutView : mSystemShortcutViews) {
        if (systemShortcutView.getTag() instanceof SystemShortcut.Widgets) {
            widgetsView = systemShortcutView;
            break;
        }
    }
    final PopupPopulator.Item widgetsItem = mSystemShortcutIcons == null
            ? PopupPopulator.Item.SYSTEM_SHORTCUT
            : PopupPopulator.Item.SYSTEM_SHORTCUT_ICON;
    if (onClickListener != null && widgetsView == null) {
        // We didn't have any widgets cached but now there are some, so enable the shortcut.
        widgetsView = mLauncher.getLayoutInflater().inflate(widgetsItem.layoutId, this, false);
        PopupPopulator.initializeSystemShortcut(getContext(), widgetsView, widgetInfo);
        widgetsView.setOnClickListener(onClickListener);
        if (widgetsItem == PopupPopulator.Item.SYSTEM_SHORTCUT_ICON) {
            addShortcutView(widgetsView, widgetsItem, 0);
        } else {
            // If using the expanded system shortcut (as opposed to just the icon), we need to
            // reopen the container to ensure measurements etc. all work out. While this could
            // be quite janky, in practice the user would typically see a small flicker as the
            // animation restarts partway through, and this is a very rare edge case anyway.
            ((PopupContainerWithArrow) getParent()).close(false);
            PopupContainerWithArrow.showForIcon(originalIcon);
        }
    } else if (onClickListener == null && widgetsView != null) {
        // No widgets exist, but we previously added the shortcut so remove it.
        if (widgetsItem == PopupPopulator.Item.SYSTEM_SHORTCUT_ICON) {
            mSystemShortcutViews.remove(widgetsView);
            mSystemShortcutIcons.removeView(widgetsView);
        } else {
            ((PopupContainerWithArrow) getParent()).close(false);
            PopupContainerWithArrow.showForIcon(originalIcon);
        }
    }
}
 
Example 19
Project: YCBaseAdapter   File: BaseRvViewHolder.java   Source Code and License Vote up 4 votes
/**
 * 关于事件的
 */
public BaseRvViewHolder setOnClickListener(int viewId, View.OnClickListener listener) {
    View view = getView(viewId);
    view.setOnClickListener(listener);
    return this;
}
 
Example 20
Project: GitHub   File: BaseViewHolder.java   Source Code and License Vote up 3 votes
/**
 * Sets the on click listener of the view.
 *
 * @param viewId   The view id.
 * @param listener The on click listener;
 * @return The BaseViewHolder for chaining.
 */
@Deprecated
public BaseViewHolder setOnClickListener(@IdRes int viewId, View.OnClickListener listener) {
    View view = getView(viewId);
    view.setOnClickListener(listener);
    return this;
}