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:Main.java

public static void openManagePictures(final Activity mContext, TextView tv, final List<String> list) {
    tv.setOnClickListener(new View.OnClickListener() {
        @Override/*  w w  w  .  j  a  v  a 2s .  c o m*/
        public void onClick(View v) {
            //                ProductPictureManager.open(mContext, list);
        }
    });
}

From source file:com.prasanna.android.stacknetwork.utils.MarkdownFormatter.java

private static void setupOnLinkClick(final Context context, final String url, final TextView textView) {
    textView.setOnClickListener(new View.OnClickListener() {
        @Override//w w w . j  av a 2 s  .  co m
        public void onClick(View v) {
            AlertDialog.Builder imageDialog = new AlertDialog.Builder(context);
            ProgressBar progressBar = new ProgressBar(context);
            imageDialog.setView(progressBar);
            AlertDialog progressDialog = imageDialog.create();
            progressDialog.show();
            new GetImageAsyncTask(new AsyncTaskCompletionNotifierImagePopup(context, progressDialog))
                    .execute(url);
        }
    });
}

From source file:com.battlelancer.seriesguide.util.PeopleListHelper.java

private static void addShowAllView(LayoutInflater inflater, ViewGroup peopleContainer,
        View.OnClickListener clickListener) {
    TextView showAllView = (TextView) inflater.inflate(R.layout.item_action_add, peopleContainer, false);
    showAllView.setText(R.string.action_display_all);
    showAllView.setOnClickListener(clickListener);
    peopleContainer.addView(showAllView);
}

From source file:eu.inmite.apps.smsjizdenka.framework.about.BaseAboutFragment.java

public static void setupLink(TextView textView, View.OnClickListener listener) {
    textView.setPaintFlags(textView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    textView.setTextColor(App.getInstance().getResources().getColorStateList(R.color.about_link_dark));
    textView.setOnClickListener(listener);
}

From source file:Main.java

/**
 * Make a textview to a collapsible textview with the indicator on the right of the textview
 * /*w ww.jav  a 2  s  .  co  m*/
 * @param tv , {@link TextView} to be converted
 * @param upDrawableResId , drawable resource id to be used as up indicator
 * @param downDrawableResId , drawable resource id to be used as down indicator
 * @param lineTreshold , no of line to be displayed for the collapsed state
 */
public static void makeCollapsible(final TextView tv, int upDrawableResId, int downDrawableResId,
        final int lineTreshold) {

    final Drawable[] drawables = tv.getCompoundDrawables();
    final Drawable up = tv.getContext().getResources().getDrawable(upDrawableResId);
    final Drawable down = tv.getContext().getResources().getDrawable(downDrawableResId);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down, drawables[3]);
        tv.setEllipsize(TruncateAt.END);
        tv.setMaxLines(lineTreshold);
        tv.setTag(true);
        tv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (v instanceof TextView) {
                    TextView tv = (TextView) v;
                    boolean snippet = (Boolean) tv.getTag();
                    if (snippet) {
                        // show everything
                        snippet = false;
                        tv.setMaxLines(Integer.MAX_VALUE);
                        tv.setEllipsize(null);
                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], up,
                                drawables[3]);
                    } else {
                        // show snippet
                        snippet = true;
                        tv.setMaxLines(lineTreshold);
                        tv.setEllipsize(TruncateAt.END);
                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down,
                                drawables[3]);
                    }
                    tv.setTag(snippet);
                }

            }
        });
    } else {
        tv.addTextChangedListener(new TextWatcher() {

            @Override
            public void afterTextChanged(Editable arg0) {

                ViewTreeObserver vto = tv.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

                    @SuppressWarnings("deprecation")
                    @SuppressLint("NewApi")
                    @Override
                    public void onGlobalLayout() {

                        tv.setEllipsize(TruncateAt.END);
                        int line = tv.getLineCount();
                        tv.setMaxLines(lineTreshold);
                        if (line <= lineTreshold) {
                            tv.setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View arg0) {
                                    // empty listener
                                    // Log.d("line count", "count: "+
                                    // tv.getLineCount());
                                }
                            });
                            if (tv.getLayout() != null) {
                                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                                    tv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                                } else {
                                    tv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                                }
                            }
                            return;
                        }

                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], down,
                                drawables[3]);
                        tv.setTag(true);
                        tv.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                if (v instanceof TextView) {
                                    TextView tv = (TextView) v;
                                    boolean snippet = (Boolean) tv.getTag();
                                    if (snippet) {
                                        snippet = false;
                                        // show everything
                                        tv.setMaxLines(Integer.MAX_VALUE);
                                        tv.setEllipsize(null);
                                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1],
                                                up, drawables[3]);
                                    } else {
                                        snippet = true;
                                        // show snippet
                                        tv.setMaxLines(lineTreshold);
                                        tv.setEllipsize(TruncateAt.END);
                                        tv.setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1],
                                                down, drawables[3]);
                                    }
                                    tv.setTag(snippet);
                                }

                            }
                        });

                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                            tv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        } else {
                            tv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    }

                });
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }

        });
    }

}

From source file:com.suyonoion.mymath.Menus.fragment_page5.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle SavedInstanceStace) {
    tampilpage5 = inflater.inflate(R.layout.page5, container, false);
    TextView dev = (TextView) tampilpage5.findViewById(R.id.dev);
    dev.setOnClickListener(new View.OnClickListener() {
        @Override/*w  w  w. ja v  a2  s .com*/
        public void onClick(View v) {
            goToDev("https://fb.com/suyono.ion");
        }
    });
    return tampilpage5;
}

From source file:com.thelastcrusade.soundstream.components.AboutFragment.java

public void listenToHttpLink(TextView linkText, final String url) {
    linkText.setOnClickListener(new AdapterView.OnClickListener() {

        @Override//  www  . j a  va  2s  .  c  om
        public void onClick(View arg0) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(browserIntent);
        }
    });
}

From source file:com.renard.ocr.help.ContactActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact);
    // Show the Up button in the action bar.
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    TextView email = (TextView) findViewById(R.id.textView_send_mail);
    email.setOnClickListener(new OnClickListener() {

        @Override/*w w  w.  j av  a2 s .  c om*/
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("message/rfc822");
            intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "text fairy feedback");
            intent.putExtra(android.content.Intent.EXTRA_EMAIL,
                    new String[] { "renard.wellnitz+textfairy@googlemail.com" });
            startActivity(intent);
        }
    });

}

From source file:de.azapps.mirakel.adapter.TagAdapter.java

@Override
public void bindView(final View v, final Context ctx, final Cursor c) {
    final Tag tag = new Tag(c);
    final TextView t = (TextView) v.findViewById(R.id.tag_list_name);
    t.setText(tag.getName());//from ww  w. j av  a 2 s  .com
    t.setOnClickListener(this.onClick);
    t.setTag(tag);
}

From source file:free.rm.skytube.gui.businessobjects.adapters.SearchHistoryCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);
    ImageButton deleteButton = view.findViewById(R.id.delete_button);
    final TextView textView = view.findViewById(android.R.id.text1);
    textView.setOnClickListener(new View.OnClickListener() {
        @Override// ww w  .  ja v  a2 s  . com
        public void onClick(View v) {
            if (searchHistoryClickListener != null)
                searchHistoryClickListener.onClick(textView.getText().toString());
        }
    });
    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // delete the previous search from the search database
            SearchHistoryDb.getSearchHistoryDb().deleteSearchText(textView.getText().toString());

            // update the search suggestions by changing the cursor (N.B cursor cannot be modified)
            Cursor cursor = SearchHistoryDb.getSearchHistoryDb().getSearchCursor(searchBarString);
            swapCursor(cursor);
        }
    });
}