Example usage for android.widget TextView setOnClickListener

List of usage examples for android.widget TextView setOnClickListener

Introduction

In this page you can find the example usage for android.widget TextView setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.androidinspain.deskclock.timer.TimerSetupView.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mTimeView = (TextView) findViewById(R.id.timer_setup_time);
    mDeleteView = findViewById(R.id.timer_setup_delete);
    mDividerView = findViewById(R.id.timer_setup_divider);
    mDigitViews = new TextView[] { (TextView) findViewById(R.id.timer_setup_digit_0),
            (TextView) findViewById(R.id.timer_setup_digit_1),
            (TextView) findViewById(R.id.timer_setup_digit_2),
            (TextView) findViewById(R.id.timer_setup_digit_3),
            (TextView) findViewById(R.id.timer_setup_digit_4),
            (TextView) findViewById(R.id.timer_setup_digit_5),
            (TextView) findViewById(R.id.timer_setup_digit_6),
            (TextView) findViewById(R.id.timer_setup_digit_7),
            (TextView) findViewById(R.id.timer_setup_digit_8),
            (TextView) findViewById(R.id.timer_setup_digit_9), };

    // Tint the divider to match the disabled control color by default and used the activated
    // control color when there is valid input.
    final Context dividerContext = mDividerView.getContext();
    final int colorControlActivated = ThemeUtils.resolveColor(dividerContext, R.attr.colorControlActivated);
    final int colorControlDisabled = ThemeUtils.resolveColor(dividerContext, R.attr.colorControlNormal,
            new int[] { ~android.R.attr.state_enabled });
    ViewCompat.setBackgroundTintList(mDividerView,
            new ColorStateList(new int[][] { { android.R.attr.state_activated }, {} },
                    new int[] { colorControlActivated, colorControlDisabled }));
    ViewCompat.setBackgroundTintMode(mDividerView, PorterDuff.Mode.SRC);

    // Initialize the digit buttons.
    final UiDataModel uidm = UiDataModel.getUiDataModel();
    for (final TextView digitView : mDigitViews) {
        final int digit = getDigitForId(digitView.getId());
        digitView.setText(uidm.getFormattedNumber(digit, 1));
        digitView.setOnClickListener(this);
    }//from   www  .  ja  v a  2 s.  c  o  m

    mDeleteView.setOnClickListener(this);
    mDeleteView.setOnLongClickListener(this);

    updateTime();
    updateDeleteAndDivider();
}

From source file:com.gh4a.activities.GistActivity.java

private void fillData(final Gist gist) {
    mGist = gist;//from  www  .j  a  v a2  s .c  om

    if (gist.getOwner() != null) {
        getSupportActionBar().setSubtitle(gist.getOwner().getLogin());
    }

    TextView tvDesc = (TextView) findViewById(R.id.tv_desc);
    tvDesc.setText(TextUtils.isEmpty(gist.getDescription()) ? getString(R.string.gist_no_description)
            : gist.getDescription());

    TextView tvCreatedAt = (TextView) findViewById(R.id.tv_created_at);
    tvCreatedAt.setText(StringUtils.formatRelativeTime(this, gist.getCreatedAt(), true));

    Map<String, GistFile> files = gist.getFiles();
    if (files != null && !files.isEmpty()) {
        ViewGroup container = (ViewGroup) findViewById(R.id.file_container);
        LayoutInflater inflater = getLayoutInflater();

        container.removeAllViews();
        for (GistFile gistFile : files.values()) {
            TextView rowView = (TextView) inflater.inflate(R.layout.selectable_label, container, false);

            rowView.setText(gistFile.getFilename());
            rowView.setTextColor(UiUtils.resolveColor(this, android.R.attr.textColorPrimary));
            rowView.setOnClickListener(this);
            rowView.setTag(gistFile);
            container.addView(rowView);
        }
    } else {
        findViewById(R.id.file_card).setVisibility(View.GONE);
    }

    findViewById(R.id.tv_private).setVisibility(gist.isPublic() ? View.GONE : View.VISIBLE);
}

From source file:com.github.crvv.wubinput.wubi.dictionary.suggestions.SuggestionStripView.java

public SuggestionStripView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.suggestions_strip, this);

    mSuggestionsStrip = (ViewGroup) findViewById(R.id.suggestions_strip);
    mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, null, null);

    for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
        final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
        word.setOnClickListener(this);
        word.setOnLongClickListener(this);
        mWordViews.add(word);/* w  w w  .j  av  a2 s  .c om*/
        final View divider = inflater.inflate(R.layout.suggestion_divider, null);
        mDividerViews.add(divider);
        final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
        info.setTextColor(Color.WHITE);
        info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
    }

    mLayoutHelper = new SuggestionStripLayoutHelper(context, attrs, defStyle, mWordViews, mDividerViews, null);

    mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
    mMoreSuggestionsView = (MoreSuggestionsView) mMoreSuggestionsContainer
            .findViewById(R.id.more_suggestions_view);
    mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);

    final Resources res = context.getResources();
    mMoreSuggestionsModalTolerance = res
            .getDimensionPixelOffset(R.dimen.config_more_suggestions_modal_tolerance);
    mMoreSuggestionsSlidingDetector = new GestureDetector(context, mMoreSuggestionsSlidingListener);

    final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, R.styleable.Keyboard, defStyle,
            R.style.SuggestionStripView);
    keyboardAttr.recycle();
}

From source file:com.money.manager.ex.assetallocation.AssetClassEditFragment.java

private void initializeAllocationPicker() {
    TextView view = viewHolder.allocationTextView;
    if (view == null)
        return;/*from   w  w w .  jav a  2s . c  o m*/

    view.setText(assetClass.getAllocation().toString());

    TextDrawable1 drawable = new TextDrawable1("%", 32.0f);
    view.setCompoundDrawables(drawable, null, null, null);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calculator.forFragment(AssetClassEditFragment.this).amount(assetClass.getAllocation())
                    .show(RequestCodes.ALLOCATION);
        }
    });
}

From source file:com.linangran.tgfcapp.activities.MainActivity.java

private void inflateForumList(List<ForumBasicData> list, LinearLayout layout) {
    if (list == null || list.size() == 0) {
        return;/*from   w w  w . ja  va 2s . c  o  m*/
    }
    LayoutInflater inflater = getLayoutInflater();
    for (int i = 0; i < list.size(); i++) {
        LinearLayout textLinearLayout = (LinearLayout) inflater.inflate(R.layout.forum_list_item, null);
        layout.addView(textLinearLayout);
        TextView textView = (TextView) textLinearLayout.findViewById(R.id.forum_list_item_textview);
        textView.setText(list.get(i).name);
        textView.setTag(list.get(i));
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ForumBasicData forumBasicData = (ForumBasicData) view.getTag();
                MainActivity.this.drawerLayout.closeDrawers();
                MainActivity.this.drawerLayout.post(new Runnable() {
                    @Override
                    public void run() {
                        MainActivity.this.drawerToggle.syncState();
                    }
                });
                MainActivity.this.forumListFragment.reload(forumBasicData);
            }
        });
    }
}

From source file:id.zelory.codepolitan.ui.fragment.ReadFragment.java

@Override
public void showArticle(Article article) {
    image.setImageUrl(article.getThumbnailMedium(), ivError);
    title.setText(Html.fromHtml(article.getTitle()));
    date.setText(article.getDateClear());
    if (article.getCategory() != null && !article.getCategory().isEmpty()) {
        category.setText(Html.fromHtml(article.getCategory().get(0).getName()));
        category.setOnClickListener(v -> onCategoryClick(article.getCategory().get(0)));
    }/*  ww  w. java 2s  .c  o m*/
    content.loadData(article.getContent());
    llTags.removeAllViews();
    int size = article.getTags().size();
    for (int i = 0; i < size; i++) {
        TextView tag = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.item_tag_read, llTags,
                false);
        tag.setText(Html.fromHtml(String.format("# %s", article.getTags().get(i).getName())));
        final int position = i;
        tag.setOnClickListener(v -> onTagClick(article.getTags().get(position)));
        llTags.addView(tag);
    }
    llRoot.setVisibility(View.VISIBLE);
    llRoot.startAnimation(animation);

    new Handler().postDelayed(() -> content.loadData(article.getContent()), 800);
}

From source file:org.ewicom.pps.unitinfo.TabAddressFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.tab_address, container, false);

    Bundle args = getArguments();/*from w ww  .jav  a  2 s .co m*/
    if (args != null) {
        this.unitID = args.getLong("unitID");
    }

    Button unitWebSite = (Button) rootView.findViewById(R.id.button_www);
    unitWebSite.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            openUnitWebsite(rootView);
        }
    });

    TextView openParent = (TextView) rootView.findViewById(R.id.text_unitparent);
    openParent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            openParent(rootView);
        }
    });

    showImage = (TextView) rootView.findViewById(R.id.link_openimg);
    showImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            downloadImageAndShow();
        }
    });

    return rootView;
}

From source file:com.google.android.apps.forscience.whistlepunk.EditNoteDialog.java

@Override
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
    mLabel = getArguments().getParcelable(KEY_SAVED_LABEL);
    String timeText = getArguments().getString(KEY_SAVED_TIME_TEXT, "");
    String timeTextContentDescription = getArguments().getString(KEY_SAVED_TIME_TEXT_DESCRIPTION);
    mTimestamp = getArguments().getLong(KEY_SAVED_TIMESTAMP);
    try {// w w w  .j av a  2 s  . c  om
        mSelectedValue = GoosciLabelValue.LabelValue.parseFrom(getArguments().getByteArray(KEY_SELECTED_VALUE));
    } catch (InvalidProtocolBufferNanoException ex) {
        Log.wtf(TAG, "Couldn't parse label value");
    }
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());

    LinearLayout rootView = (LinearLayout) LayoutInflater.from(getActivity())
            .inflate(R.layout.run_review_label_edit, null);
    alertDialog.setView(rootView);

    ImageView imageView = (ImageView) rootView.findViewById(R.id.picture_note_preview_image);
    final EditText editText = (EditText) rootView.findViewById(R.id.edit_note_text);
    TextView autoTextView = (TextView) rootView.findViewById(R.id.auto_note_text);

    // Use mSelectedValue to load content, because the user may have changed the value since
    // it was stored in the label. Note that picture labels can't be edited at this time,
    // but in the future this will apply to picture labels as well.
    if (mLabel instanceof PictureLabel) {
        imageView.setVisibility(View.VISIBLE);
        autoTextView.setVisibility(View.GONE);
        editText.setText(PictureLabel.getCaption(mSelectedValue));
        editText.setHint(R.string.picture_note_caption_hint);
        Glide.with(getActivity()).load(PictureLabel.getFilePath(mSelectedValue)).into(imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PictureUtils.launchExternalViewer(getActivity(), (PictureLabel.getFilePath(mSelectedValue)));
            }
        });
    } else if (mLabel instanceof TextLabel) {
        imageView.setVisibility(View.GONE);
        autoTextView.setVisibility(View.GONE);
        editText.setText(TextLabel.getText(mSelectedValue));
    } else if (mLabel instanceof SensorTriggerLabel) {
        imageView.setVisibility(View.GONE);
        autoTextView.setVisibility(View.VISIBLE);
        editText.setText(SensorTriggerLabel.getCustomText(mSelectedValue));
        String autoText = SensorTriggerLabel.getAutogenText(mSelectedValue);
        TriggerHelper.populateAutoTextViews(autoTextView, autoText, R.drawable.ic_label_black_24dp,
                getResources());
    }

    alertDialog.setPositiveButton(R.string.action_save, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            mLabel.setTimestamp(mTimestamp);
            if (mLabel instanceof TextLabel) {
                ((TextLabel) mLabel).setText(editText.getText().toString());
            } else if (mLabel instanceof PictureLabel) {
                ((PictureLabel) mLabel).setCaption(editText.getText().toString());
            } else if (mLabel instanceof SensorTriggerLabel) {
                ((SensorTriggerLabel) mLabel).setCustomText(editText.getText().toString());
            }
            getDataController().editLabel(mLabel,
                    ((EditNoteDialogListener) getParentFragment()).onLabelEdit(mLabel));
        }
    });
    alertDialog.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    alertDialog.setCancelable(true);

    TextView timeTextView = (TextView) rootView.findViewById(R.id.edit_note_time);
    timeTextView.setText(timeText);
    timeTextView.setContentDescription(timeTextContentDescription);
    if (labelBelongsToRun() && mLabel.canEditTimestamp()) {
        timeTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GoosciLabelValue.LabelValue value = new GoosciLabelValue.LabelValue();
                if (mLabel instanceof PictureLabel) {
                    // Captions can be edited, but the picture path cannot be edited at this
                    // time.
                    PictureLabel.populateStorageValue(value, ((PictureLabel) mLabel).getFilePath(),
                            editText.getText().toString());
                    ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value,
                            mTimestamp);
                } else if (mLabel instanceof TextLabel) {
                    TextLabel.populateStorageValue(value, editText.getText().toString());
                    ((EditNoteDialogListener) getParentFragment()).onEditNoteTimestampClicked(mLabel, value,
                            mTimestamp);
                }
            }
        });
    } else if (labelBelongsToRun()) {
        Drawable lockDrawable = getResources().getDrawable(R.drawable.ic_lock_black_18dp);
        DrawableCompat.setTint(lockDrawable, getResources().getColor(R.color.text_color_light_grey));
        // There is already a start drawable. Use it again.
        Drawable[] drawables = timeTextView.getCompoundDrawablesRelative();
        timeTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawables[0], null, lockDrawable, null);
    }

    AlertDialog dialog = alertDialog.create();
    if (mLabel instanceof TextLabel || mLabel instanceof SensorTriggerLabel) {
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    }
    return dialog;
}

From source file:com.bt.download.android.gui.adapters.SearchResultListAdapter.java

protected void populateAppiaPart(View view, AppiaSearchResult sr) {
    TextView adIndicator = findView(view, R.id.view_bittorrent_search_result_list_item_ad_indicator);
    adIndicator.setVisibility(View.VISIBLE);

    TextView extra = findView(view, R.id.view_bittorrent_search_result_list_item_text_extra);
    extra.setText(sr.getCategoryName() + " : " + sr.getDescription());

    //TextView seeds = findView(view, R.id.view_bittorrent_search_result_list_item_text_seeds);
    //String license = sr.getLicense().equals(License.UNKNOWN) ? "" : " - " + sr.getLicense();

    TextView sourceLink = findView(view, R.id.view_bittorrent_search_result_list_item_text_source);
    sourceLink.setText(sr.getSource());/*from   w w  w  . ja  v a  2  s  .c  o m*/
    sourceLink.setTag(sr.getDetailsUrl());
    sourceLink.setPaintFlags(sourceLink.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    sourceLink.setOnClickListener(linkListener);
}

From source file:fr.free.nrw.commons.media.MediaDetailFragment.java

private View buildCatLabel(String cat) {
    final String catName = cat;
    final View item = getLayoutInflater(null).inflate(R.layout.detail_category_item, null, false);
    final TextView textView = (TextView) item.findViewById(R.id.mediaDetailCategoryItemText);

    textView.setText(cat);/* w w  w  . j  av  a 2  s  . c  om*/
    if (categoriesLoaded && categoriesPresent) {
        textView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String selectedCategoryTitle = "Category:" + catName;
                Intent viewIntent = new Intent();
                viewIntent.setAction(Intent.ACTION_VIEW);
                viewIntent.setData(Utils.uriForWikiPage(selectedCategoryTitle));
                startActivity(viewIntent);
            }
        });
    }
    return item;
}