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.huahan.hhbaseutils.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);/*from www. j  a  v  a2  s.c om*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    if (isSingleLine) {
        tab.setSingleLine();
    }

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:com.android.yijiang.kzx.widget.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext(), null, android.R.attr.textAppearanceMedium);
    tab.setText(title);//from  w w w  .  ja v  a2 s .  co m
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:com.chenupt.springindicator.SpringIndicator.java

private void addTabItems() {
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<TextView>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null) {
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        }/*from   ww  w  .j a  v a2s .  co m*/
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0) {
            textView.setBackgroundResource(textBgResId);
        }
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position)) {
                    viewPager.setCurrentItem(position);
                }
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:com.nadmm.airports.FragmentBase.java

protected void makeClickToCall(TextView tv) {
    PackageManager pm = mActivity.getPackageManager();
    boolean hasTelephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
    if (hasTelephony && tv.getText().length() > 0) {
        UiUtils.setTextViewDrawable(tv, R.drawable.ic_phone);
        tv.setTag(Intent.ACTION_DIAL);// www  . j  a  va  2 s  . c  o m
        tv.setOnClickListener(mOnPhoneClickListener);
    } else {
        UiUtils.removeTextViewDrawable(tv);
        tv.setOnClickListener(null);
    }
}

From source file:fr.mixit.android.ui.fragments.SessionDetailsFragment.java

@TargetApi(Build.VERSION_CODES.FROYO)
protected void displayInterests(Cursor c) {
    mInterests.removeAllViews();/*from   w w w  .j  av a  2  s . c  om*/

    final Context ctx = getActivity();
    if (ctx == null) {
        return;
    }

    final LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    final int margin = ctx.getResources().getDimensionPixelSize(R.dimen.margin_small);
    lp.setMargins(0, margin, 0, 0);

    final LayoutInflater inflater = LayoutInflater.from(ctx);

    if (c != null && c.moveToFirst()) {
        do {
            final String interestId = c.getString(MixItContract.Interests.PROJ.INTEREST_ID);
            final String interestName = c.getString(MixItContract.Interests.PROJ.NAME);

            final TextView interestView = (TextView) inflater.inflate(R.layout.item_interest, mInterests,
                    false);
            interestView.setText(interestName);
            interestView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    onInterestItemClick(interestId, interestName);
                }
            });
            mInterests.addView(interestView, lp);
        } while (c.moveToNext());
    } else {
        inflater.inflate(R.layout.empty_text_view, mInterests, true);
        final TextView emptyView = (TextView) mInterests.findViewById(R.id.empty_text_view);
        emptyView.setText(R.string.sessions_empty_interests);
    }
}

From source file:cn.com.incito.driver.UI.detailDialog.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);/*from   www  .ja v a2  s  .  c om*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1));
    tab.setSingleLine();

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:PagerSlidingTab.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);//from  w w  w .  j a  va 2  s . c o m
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    tab.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1));

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:cc.metapro.openct.customviews.DuringDialog.java

private void setViews(GridLayout gridLayout) {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 6; j++) {
            final int week = i * 6 + j + 1;
            final TextView textView = new TextView(getActivity());
            textView.setText(week + gridLayout.getContext().getString(R.string.week));
            textView.setGravity(Gravity.CENTER);
            if (DURING[week]) {
                textView.setBackground(//w ww. jav a  2 s  . com
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_blue));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
            } else {
                textView.setBackground(
                        ContextCompat.getDrawable(getActivity(), R.drawable.text_view_card_style_grey));
                textView.setTextColor(ContextCompat.getColor(getActivity(), R.color.material_grey));
            }

            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    DURING[week] = !DURING[week];
                }
            });
            GridLayout.Spec row = GridLayout.spec(i, 1, 1);
            GridLayout.Spec col = GridLayout.spec(j, 1, 1);
            GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col);
            gridLayout.addView(textView, params);
            selections[i][j] = textView;
        }
    }
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothFixTabView.java

/**
 * ??tab./*  w  ww. ja v a 2s.  co m*/
 *
 * @param tabTexts the tab texts
 * @param fragments the fragments
 */
public void addItemViews(List<String> tabTexts, List<Fragment> fragments) {

    tabItemTextList.addAll(tabTexts);
    pagerItemList.addAll(fragments);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);

}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothFixTabView.java

/**
 * ??tab./*  w  ww.j  a v a 2 s  .c o  m*/
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    AbLogUtil.d(AbSlidingSmoothFixTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}