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:android.view.SpringIndicator.java

private void addTabItems() {
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        final TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null)
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        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/*from  w  ww.  ja v a2s .c o m*/
            public void onClick(final View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position))
                    viewPager.setCurrentItem(position);
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:com.cybrosys.currency.CurrencyMain.java

public void onStart() {
    super.onStart();
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    linlaHeaderProgress = (LinearLayout) getView().findViewById(R.id.linlaHeaderProgress);
    imgvHead = (ImageView) getView().findViewById(R.id.imageHead);
    txtvHead = (TextView) getView().findViewById(R.id.textHead);
    lstvMainlistView = (ListView) getView().findViewById(R.id.listview);
    etxtText = (EditText) getView().findViewById(R.id.editText1);
    slide = (SlidingDrawer) getView().findViewById(R.id.SlidingDrawer);
    TableLayout tablePad = (TableLayout) getView().findViewById(R.id.tablone);
    int inPadCount = tablePad.getChildCount();
    for (int i = 0; i < inPadCount; i++) {
        View v = tablePad.getChildAt(i);
        if (v instanceof TableRow) {
            TableRow row = (TableRow) v;
            int rowCount = row.getChildCount();

            for (int r = 0; r < rowCount; r++) {
                View v2 = row.getChildAt(r);

                if (v2 instanceof Button) {
                    Button b = (Button) v2;
                    b.setOnClickListener(buttonpad);
                } else if (v2 instanceof TextView) {
                    TextView txtv = (TextView) v2;
                    txtv.setOnClickListener(null);
                }//from  w  w w.j av  a  2  s.  c o  m
            }
        }
    }
    isFlag2 = true;
    Settings = getActivity().getSharedPreferences(strPREFERNAME, 0);
    for (int inI = 0; inI <= 5; inI++) {
        if (Settings.getString("val" + inI, "").equals("") && Settings.getString("CrnCode" + inI, "").equals("")
                && Settings.getString("flag" + inI, "").equals("")) {
            isFlag2 = false;
        }

    }
    if (isFlag2 == true) {
        Sharepreferences();
    } else {
        CustomListView();
        if (isConnection() == true) {
        } else {
            isFlag2 = true;
            isFlag = true;
            Toast.makeText(getActivity(), "No Internet Conection", Toast.LENGTH_LONG).show();
        }
    }
    SharedPreferences prefs = PalmCalcActivity.ctx.getSharedPreferences("UpdateTime", 0);
    lastUpdateTime = prefs.getLong("lastUpdateTime", 0);
    if ((lastUpdateTime) <= System.currentTimeMillis()) {
        lastUpdateTime = System.currentTimeMillis();
        SharedPreferences.Editor editors = prefs.edit();
        editors.putLong("lastUpdateTime", lastUpdateTime);
        editors.commit();
        if (isConnection() == true) {
            new BackProsess().execute(getActivity());
        }
    }
    etxtText.addTextChangedListener(textwach);
    aList = new ArrayList<HashMap<String, String>>();
    for (int InI = 0; InI < 5; InI++) {
        hm = new HashMap<String, String>();
        hm.put("flag", Integer.toString(fltFlags[InI]));
        if (InI != 5) {
            hm.put("cur", strCrnCode[InI].substring(0, 3));
        } else {
            hm.put("cur", strCrnCode[InI]);
        }
        aList.add(hm);
    }
    txtvHead.setText(strCrnCode[5]);
    imgvHead.setImageResource(fltFlags[5]);
    adapter = new ListAdapter1(getActivity(), aList);
    lstvMainlistView.setAdapter(adapter);
    lstvMainlistView.setOnItemClickListener(ListsingleClick);
    lstvMainlistView.setOnItemLongClickListener(ListLongClick);
    Decimalpoint();
    View vwMain = (View) getActivity().findViewById(R.id.idCurrencyMain);
    vwMain.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            slide.close();
            return true;
        }
    });
    etxtText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!slide.isOpened()) {
                slide.open();
            }
        }
    });
    if (!Settings.getString("Input", "").equals("")) {
        calculation(Double.parseDouble(Settings.getString("Input", "")));
        etxtText.setText("");
        etxtText.setText(Settings.getString("Input", ""));
    } else {
        etxtText.setText(Settings.getString("Input", "1"));
    }
}

From source file:com.yahala.ui.GroupCreateActivity.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.group_create_menu, menu);
    SupportMenuItem doneItem = (SupportMenuItem) menu.findItem(R.id.done_menu_item);
    TextView doneTextView = (TextView) doneItem.getActionView().findViewById(R.id.done_button);
    doneTextView.setText(LocaleController.getString("Next", R.string.Next));
    doneTextView.setOnClickListener(new View.OnClickListener() {
        @Override//from   w w w.j  a  v a2s  . com
        public void onClick(View view) {

            if (!selectedContacts.isEmpty()) {
                ArrayList<String> result = new ArrayList<String>();
                result.addAll(selectedContacts.keySet());
                Bundle args = new Bundle();
                args.putStringArrayList("result", result);
                FileLog.e("selectedContacts.size()", selectedContacts.size() + "");
                GroupCreateFinalActivity groupCreateFinalActivity = new GroupCreateFinalActivity();
                groupCreateFinalActivity.setArguments(args);
                ((LaunchActivity) parentActivity).presentFragment(groupCreateFinalActivity,
                        "group_create_final", false);

            } else {
                return;
            }

        }
    });
}

From source file:com.hybunion.member.view.PagerSlidingTabStrip.java

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

    TextView tab = new TextView(getContext());
    tab.setWidth(screenWidth / tabCount);// 
    tab.setText(title);/*  w  w w  .  j  av a2 s . c  o  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.ranger.bmaterials.view.PagerSlidingTabStrip.java

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

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

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (clickListener != null)
                clickListener.onClick(position, title);

            pager.setCurrentItem(position, false);

            currentPosition = position;
            currentPositionOffset = 0;
            scrollToChild(position, 0);
            invalidate();

        }
    });

    tabsContainer.addView(tab);

}

From source file:com.fitme.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.options, menu);
    MenuItem mi = menu.findItem(R.id.menu_spinner_active_program);
    final TextView tv = (TextView) mi.getActionView();
    ActiveProgramDAO apd = new ActiveProgramDAO(MainActivity.this);
    activeProgram = apd.getActiveProgramName();
    tv.setText(activeProgram);/*from  w  w w .jav  a2  s .c o  m*/

    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.setTitle(getText(R.string.title_select_prog_dialog));
            View programView = getLayoutInflater().inflate(R.layout.programs_list, null);
            ExpandableListView elv = (ExpandableListView) programView.findViewById(R.id.list_programs);
            final ProgramListAdapter pda = new ProgramListAdapter(MainActivity.this);
            elv.setAdapter(pda);
            // Setting listener for Add Program button
            Button addProgram = (Button) programView.findViewById(R.id.button_add_program);
            addProgram.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    onAddProgramRequested(pda);
                }
            });
            elv.setGroupIndicator(null);
            elv.setOnGroupClickListener(null);
            elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition,
                        int childPosition, long l) {
                    pda.setProgramSelected(groupPosition, childPosition);
                    onNewProgramSelected(pda.getSelectedProgramName());
                    // Refresh trainings section list
                    TrainingsSectionFragment tsf = (TrainingsSectionFragment) mAppSectionsPagerAdapter
                            .getItem(AppSectionsPagerAdapter.SECTION_TRAININGS);
                    tsf.onNewProgramSelected();
                    dialog.dismiss();
                    return false;
                }
            });
            dialog.setContentView(programView);
            dialog.show();
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT);
        }
    });

    return true;
}

From source file:com.google.samples.apps.iosched.videolibrary.VideoLibraryFilteredFragment.java

/**
 * Generates RadioButton for each item of the {@code values} list and adds them to the
 * {@code radioGroup}. The item equals to {@code selectedValue} will be checked initially. Items
 * with special Labels can be added using {@code specialValues}. They will be added on top and
 * in uppercase characters.//from  w w  w.  ja  va2  s  .  c  om
 */
private <T extends Comparable> void updateRadioGroup(final RadioGroup radioGroup, List<T> values,
        T selectedValue, Map<T, String> specialValues) {

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (radioGroup == null) {
        return;
    }

    // Add special Values to the list
    List<T> specialItemsList = new ArrayList<>(specialValues.keySet());
    Collections.sort(specialItemsList);
    for (T keys : specialItemsList) {
        values.add(0, keys);
    }

    radioGroup.removeAllViews();
    int idCounter = 0;
    for (final T value : values) {
        View buttonLayout = inflater.inflate(R.layout.video_library_filter_radio_button, radioGroup, false);
        final RadioButton button = (RadioButton) buttonLayout.findViewById(R.id.button);
        radioGroup.addView(buttonLayout);

        // Set the Label of the Radio Button.
        TextView text = (TextView) buttonLayout.findViewById(R.id.text);
        text.setText(specialValues.get(value) == null ? value.toString() : specialValues.get(value));

        // We have to give different IDs to all the RadioButtons inside the RadioGroup so that
        // only one can be checked at a time.
        button.setId(idCounter);
        idCounter++;

        // Trigger a RadioButton click when clicking the Text.
        text.setOnClickListener(new View.OnClickListener() {
            @Override
            @TargetApi(15)
            public void onClick(View v) {
                button.callOnClick();
            }
        });

        // When Clicking the RadioButton filter when re-filter the videos.
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                radioGroup.check(button.getId());
                onVideoFilterChanged(value);
            }
        });

        if (selectedValue.equals(value)) {
            radioGroup.check(button.getId());
        }
    }
}

From source file:com.sutromedia.android.core.PhotoActivity.java

public void onSetupView(View view, int viewId) {
    final IPhoto photo = getCurrentPhoto();
    if (photo != null) {

        int backgroundId = (viewId == R.layout.image_view_inside) ? R.drawable.attrib_inside
                : R.drawable.attrib_outside;

        Drawable background = getResources().getDrawable(backgroundId);
        background.setAlpha(155);//from   w  w w.ja v  a  2s  .  c o m
        view.findViewById(R.image.licenseGroup).setBackgroundDrawable(background);
        setVisibility(view, R.image.caption, !mInSlideShow && !isSubsetOnEntry());
        TextView caption = (TextView) view.findViewById(R.image.caption);
        String entryName = photo.getEntryName();
        if (entryName != null) {
            entryName = entryName.replace(' ', '\u00A0');
            entryName += "\u00A0\u00A0\u25B6";
        }
        caption.setText(entryName);
        caption.setSingleLine(true);
        caption.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                onReceiveEntry(new NavigationDetailWeb(photo.getEntryId()));
            }
        });

        setVisibility(view, R.image.licenseGroup, !mInSlideShow);
        Integer[] icons = PhotoLicence.getIcons(photo);
        setImageView(view, R.image.license1, 0, icons);
        setImageView(view, R.image.license2, 1, icons);
        TextView owner = (TextView) view.findViewById(R.image.owner);
        if (icons.length > 0) {
            owner.setText(photo.getAuthor());
        } else {
            view.findViewById(R.image.licenseGroup).setVisibility(View.GONE);
        }

        String url = photo.getUrl();
        View licenceGroup = view.findViewById(R.image.licenseGroup);
        if (url != null && url.length() > 0) {
            owner.setTextColor(Color.rgb(0x19, 0x49, 0x90));
            owner.setTypeface(null, Typeface.BOLD);

            licenceGroup.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    onReceiveEntry(new NavigationWeb(photo.getUrl()));
                }
            });
        } else {
            owner.setTypeface(null, Typeface.NORMAL);
            owner.setTextColor(Color.WHITE);
            licenceGroup.setOnClickListener(null);
        }

        setupTouchOnPlayButton();
        setVisibility(R.image.play_slideshow, !mInSlideShow && mShowSlideShowControls);
        setVisibility(R.image.loading, mMissingPhoto);
        setVisibility(R.image.wait, mMissingPhoto && isOnline());

        String missingTextTemplate = getString(
                mMissingPhoto && isOnline() ? R.string.missing_photo : R.string.missing_not_online);
        String missingText = String.format(missingTextTemplate, mCurrentImage + 1, getImageCountInSet());

        setText(R.image.missing, missingText);
    }
}

From source file:com.example.testing.myapplication.module.pageSliding.PagerSlidingTabStrip.java

private void addTextTab(final int position, final String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);// ww w.  ja  va  2  s .c  o  m
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

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

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

    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tab.setBackgroundResource(tabBackgroundResId);
    tab.setTextColor(mTabTextColor);
    tab.setTextSize(tabTextSize);
    //tab.setTypeface(tabTypeface, tabTypefaceStyle);

    tab.setSelected(position == 0);

    // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
    // pre-ICS-build
    if (textAllCaps) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            tab.setAllCaps(true);
        } else {
            tab.setText(tab.getText().toString().toUpperCase(locale));
        }
    }

    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

From source file:com.android.talkback.tutorial.TutorialLessonFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    int layoutId;
    if (mExercise.needScrollableContainer()) {
        layoutId = R.layout.tutorial_lesson_fragment_scrollable;
    } else {//from  w  w  w .j a  va2s  . c  om
        layoutId = R.layout.tutorial_lesson_fragment;
    }
    View view = inflater.inflate(layoutId, container, false);

    mDescription = (TextView) view.findViewById(R.id.description);
    mDescription.setText(mPage.getDescription());

    TextView subTitle = (TextView) view.findViewById(R.id.part_subtitle);
    subTitle.setText(mPage.getSubtitle());

    TextView currentPage = (TextView) view.findViewById(R.id.current_page);
    TextView next = (TextView) view.findViewById(R.id.next);
    if (mCurrentPage < mLesson.getPagesCount() - 1) {
        next.setText(R.string.tutorial_next);
        currentPage.setVisibility(View.VISIBLE);
        currentPage.setText(
                getString(R.string.tutorial_page_number_of, mCurrentPage + 1, mLesson.getPagesCount() - 1));
    } else if (mTutorialController.getNextLesson(mLesson) == null) {
        next.setText(R.string.tutorial_home);
    } else {
        next.setText(R.string.tutorial_next_lesson);
    }
    next.setOnClickListener(this);

    View previous = view.findViewById(R.id.previous_page);
    previous.setOnClickListener(this);
    previous.setContentDescription(getString(R.string.tutorial_previous));

    ViewGroup contentContainer = (ViewGroup) view.findViewById(R.id.practice_area);
    View contentView = mPage.getExercise().getContentView(inflater, contentContainer);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    contentContainer.addView(contentView, params);

    return view;
}