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.android.nsboc.ComposeFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (mItem != null) {
        switch (mItem.id + "") {
        case "1":
            mRootView = inflater.inflate(R.layout.form_unlicensed, container, false);
            break;
        case "2":
            mRootView = inflater.inflate(R.layout.form_salon, container, false);
            break;
        }/*from www. j av  a 2s. co m*/
    }

    showCurrentDateInEditText();

    ToggleButton complianceToggle = (ToggleButton) mRootView.findViewById(R.id.compliance_toggle);
    if (complianceToggle != null) {
        final LinearLayout complianceContainer = (LinearLayout) mRootView
                .findViewById(R.id.compliance_container);

        complianceToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!isChecked) {
                    complianceContainer.setVisibility(View.VISIBLE);

                    final LinearLayout complianceLayout = (LinearLayout) View.inflate(getActivity(),
                            R.layout.compliance_layout, null);

                    Spinner violationTypeSpinner = (Spinner) complianceLayout
                            .findViewById(R.id.violation_type_spinner);
                    violationTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            switch (position) {
                            case 0:
                                complianceLayout.findViewById(R.id.type_citation_container)
                                        .setVisibility(View.VISIBLE);
                                break;
                            case 1:
                                complianceLayout.findViewById(R.id.type_citation_container)
                                        .setVisibility(View.GONE);
                                break;
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                        }
                    });

                    ToggleButton anotherToggle = (ToggleButton) complianceLayout
                            .findViewById(R.id.compliance_toggle);
                    anotherToggle.setOnCheckedChangeListener(getNextToggleListener(complianceLayout));

                    complianceContainer.addView(complianceLayout);
                } else {
                    complianceContainer.setVisibility(View.GONE);
                }
            }
        });
    }

    ToggleButton emailToggle = (ToggleButton) mRootView.findViewById(R.id.emailTo_toggle);
    if (emailToggle != null) {
        final LinearLayout emailLayout = (LinearLayout) mRootView.findViewById(R.id.emailTo_layout);

        emailToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    emailLayout.setVisibility(View.VISIBLE);
                } else {
                    emailLayout.setVisibility(View.GONE);
                }
            }
        });
    }

    final TextView noticeTextView = (TextView) mRootView.findViewById(R.id.notice_textview);
    if (noticeTextView != null) {
        noticeTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (noticeTextView.getCurrentTextColor() == Color.BLACK) {
                    noticeTextView.setText(R.string.civil_citation_header);
                    noticeTextView.setTextColor(Color.parseColor("#17405e"));
                    noticeTextView.setText(Html.fromHtml("<u>" + noticeTextView.getText() + "</u>"));
                    mRootView.findViewById(R.id.civil_citation).requestFocus();
                } else {
                    noticeTextView.setText(R.string.civil_citation_notice);
                    noticeTextView.setMaxLines(Integer.MAX_VALUE);
                    noticeTextView.setTextColor(Color.BLACK);
                    noticeTextView.setText(
                            noticeTextView.getText().toString().replace("<u>", "").replace("</u>", ""));
                }
            }
        });
    }

    Spinner stateSpinner = (Spinner) mRootView.findViewById(R.id.state);
    if (stateSpinner != null) {
        stateSpinner.setSelection(27);
    }

    return mRootView;
}

From source file:com.abid_mujtaba.fetchheaders.AccountsActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.accounts);//from w  w  w.jav  a 2  s.  com

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    LinearLayout accountList = (LinearLayout) findViewById(R.id.account_list);

    LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for (int ii = 0; ii < Account.numberOfAccounts(); ii++) {
        TextView tv = (TextView) li.inflate(R.layout.account_setting_name, null);
        tv.setText(Account.get(ii).name());
        tv.setId(ii); // Store the account_id as the view id
        tv.setOnCreateContextMenuListener(onCreateContextMenuListener);
        tv.setOnTouchListener(onTouchListener);

        tv.setOnClickListener(listener);

        accountList.addView(tv);
    }
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View root = inflater.inflate(R.layout.list_content, container, false);
    mAnimator = (ViewAnimator) root.findViewById(R.id.list_animator);
    mListView = (ListView) root.findViewById(android.R.id.list);
    final TextView emptyV = (TextView) root.findViewById(android.R.id.empty);
    emptyV.setText(R.string.empty_my_planning);
    emptyV.setOnClickListener(new OnClickListener() {

        @Override/*from w  w  w .j a va2s .c om*/
        public void onClick(View v) {
            showWarningBeforeImportingStarredSession();
        }
    });
    return root;
}

From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java

private TextView getEditView(final Feature feature, final String fieldName, EDataType type, String value) {
    final TextView editView;
    switch (type) {
    case DATE://from  w  ww .j  ava2s. c o  m
        editView = new TextView(context);
        editView.setInputType(InputType.TYPE_CLASS_DATETIME);
        editView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FeaturePageAdapter.this.openDatePicker((EditText) view);
            }
        });
        if (value == null || value.equals("")) {
            value = "____-__-__";
        }
        break;
    default:
        editView = new EditText(context);
        break;
    }
    editView.setText(value);

    switch (type) {
    case DOUBLE:
    case FLOAT:
        editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        break;
    case PHONE:
        editView.setInputType(InputType.TYPE_CLASS_PHONE);
        break;
    case DATE:
        editView.setInputType(InputType.TYPE_CLASS_DATETIME);
        editView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FeaturePageAdapter.this.openDatePicker((TextView) view);
            }
        });
        break;
    case INTEGER:
        editView.setInputType(InputType.TYPE_CLASS_NUMBER);
        break;
    default:
        break;
    }
    editView.addTextChangedListener(new TextWatcher() {
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // ignore
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // ignore
        }

        public void afterTextChanged(Editable s) {
            String text = editView.getText().toString();
            feature.setAttribute(fieldName, text);
        }
    });

    return editView;
}

From source file:de.measite.contactmerger.MergeActivity.java

public void updateList() {
    progressContainer = findViewById(R.id.progress_bar_container);
    progressBar = (ProgressBar) findViewById(R.id.analyze_progress);
    progressContainer.setVisibility(View.GONE);

    loadText = (TextView) findViewById(R.id.load_text);

    TextView stopScan = (TextView) findViewById(R.id.stop_scan);
    Typeface font = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
    stopScan.setTypeface(font);/*www . j a va  2 s  .  c o m*/
    stopScan.setClickable(true);
    stopScan.setOnClickListener(this);

    startScan = (Button) findViewById(R.id.start_scan);
    startScan.setOnClickListener(this);

    ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.switcher);
    ViewSwitcher switcher_list = (ViewSwitcher) findViewById(R.id.switcher_list);

    Context context = getApplicationContext();
    File path = context.getDatabasePath("contactsgraph");
    File modelFile = new File(path, "model.kryo.gz");

    if (path.exists() && modelFile.exists()) {
        this.adapter.update();
        while (switcher.getCurrentView().getId() != R.id.switcher_list) {
            switcher.showNext();
        }
        if (adapter.getCount() == 0) {
            while (switcher_list.getCurrentView().getId() != R.id.all_done) {
                switcher_list.showNext();
            }
        } else {
            while (switcher_list.getCurrentView().getId() != R.id.contact_merge_list) {
                switcher_list.showPrevious();
            }
        }
        switcher_list.postInvalidate();
    } else {
        if (switcher.getCurrentView().getId() == R.id.contact_merge_list) {
            switcher.showPrevious();
        }
        Intent intent = new Intent(getApplicationContext(), AnalyzerService.class);
        intent.putExtra("forceRunning", true);
        startService(intent);
    }
    switcher.postInvalidate();
}

From source file:ch.pantas.billsplitter.ui.FixedTabsView.java

private void addTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);/*from www .  ja  v a2 s .  c  om*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1f));

    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab, position);
}

From source file:com.bordengrammar.bordengrammarapp.ParentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_parents, container, false);
    mail = (LinearLayout) root.findViewById(R.id.linmail);
    call = (LinearLayout) root.findViewById(R.id.lincall);
    call.setOnClickListener(new View.OnClickListener() {
        @Override//from w w w.  j  a  va  2 s . c om
        public void onClick(View arg0) {
            Intent cally = new Intent(Intent.ACTION_CALL);
            cally.setData(Uri.parse("tel:01795424192"));
            startActivity(cally);
        }
    });
    mail.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setTitle("Send a email to Borden Grammar");
            alert.setMessage("Message: ");
            final EditText input = new EditText(getActivity());
            alert.setView(input);
            alert.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String value = input.getText().toString();
                    // Do something with value!
                    Intent email = new Intent(Intent.ACTION_SEND);
                    email.setType("plain/text");
                    email.putExtra(android.content.Intent.EXTRA_EMAIL,
                            new String[] { "school@bordengrammar.kent.sch.uk" });
                    email.putExtra(Intent.EXTRA_SUBJECT, "Email (Sent From BGS APP) ");
                    email.putExtra(Intent.EXTRA_TEXT, value);
                    startActivity(Intent.createChooser(email, "Choose an Email client :"));
                }
            });
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Canceled.
                }
            });
            alert.show();
        }

    });

    URL url = null;
    try {
        url = new URL(
                "http://website.bordengrammar.kent.sch.uk/index.php?option=com_rubberdoc&view=category&id=63%3Aletters&Itemid=241&format=feed&type=rss");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    Feed feed = null;
    try {
        feed = FeedParser.parse(url);
    } catch (FeedIOException e) {
        e.printStackTrace();
    } catch (FeedXMLParseException e) {
        e.printStackTrace();
    } catch (UnsupportedFeedException e) {
        e.printStackTrace();
    }
    Boolean nully = false;
    for (int i = 0; i < 3; i++) {
        try {
            FeedItem item = feed.getItem(i);
        } catch (NullPointerException e) {
            e.printStackTrace();
            nully = true;
            Toast.makeText(getActivity().getApplicationContext(),
                    "Some features of this app require a internet connection", Toast.LENGTH_LONG).show();
        }
    }
    if (!nully) {
        final FeedItem post1 = feed.getItem(1);
        final FeedItem post2 = feed.getItem(2);
        final FeedItem post3 = feed.getItem(3);
        TextView title1 = (TextView) root.findViewById(R.id.title1);
        TextView title2 = (TextView) root.findViewById(R.id.title2);
        TextView title3 = (TextView) root.findViewById(R.id.title3);
        title1.setText(post1.getTitle());
        title2.setText(post2.getTitle());
        title3.setText(post3.getTitle());
        TextView link1 = (TextView) root.findViewById(R.id.link1);
        TextView link2 = (TextView) root.findViewById(R.id.link2);
        TextView link3 = (TextView) root.findViewById(R.id.link3);
        link1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post1.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });
        link2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post2.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });
        link3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url1 = post3.getLink().toString();
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.parse(url1), "text/html");
                startActivity(intent);
            }
        });

    } else {
        TextView title1 = (TextView) root.findViewById(R.id.title1);
        TextView title2 = (TextView) root.findViewById(R.id.title2);
        TextView title3 = (TextView) root.findViewById(R.id.title3);
        title1.setText("No connection");
        title2.setText("No connection");
        title3.setText("No connection");
    }
    TextView reader = (TextView) root.findViewById(R.id.reader);
    reader.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String appPackageName = "com.adobe.reader"; // getPackageName() from Context or Activity object
            try {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
            }
        }
    });

    return root;
}

From source file:fi.aalto.trafficsense.trafficsense.ui.AboutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TrafficSenseApplication.refreshStadi();
    mContext = this;

    setContentView(R.layout.activity_about);
    // setupActionBar(); // Not in application theme, throws an exception
    Toolbar myToolbar = (Toolbar) findViewById(R.id.about_toolbar);
    setSupportActionBar(myToolbar);/*from ww  w  .  j  av  a  2 s .  c om*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //        final View controlsView = findViewById(R.id.abt_Buttons);
    //        final View titleView = findViewById(R.id.abt_pageTitleField);
    final Button okButton = (Button) findViewById(R.id.abt_ok_button);
    final TextView legal = (TextView) findViewById(R.id.abt_legalNotice);

    // Upon interacting with UI controls, delay any scheduled hide()
    // operations to prevent the jarring behavior of controls going away
    // while interacting with the UI.
    //        okButton.setOnTouchListener(mTouchListener);

    legal.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mClickCounter++;
            //                Timber.d("mClickCounter: %d", mClickCounter);
        }
    });

    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // close
            finish();
        }
    });

    okButton.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            if (mClickCounter == 5) { // Open debug mode
                SharedPreferences.Editor mPrefEditor = getDefaultSharedPreferences(mContext).edit();
                mPrefEditor.putBoolean(getResources().getString(R.string.debug_settings_debug_mode_key), true);
                mPrefEditor.commit();
                Toast.makeText(mContext, mContext.getResources().getString(R.string.debug_mode_open),
                        Toast.LENGTH_LONG).show();
            }
            return true;
        }
    });

    // Init fields
    initFields();
}

From source file:com.example.dell.chihuobao.fragment.SettingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    hashMap = user.getUser();/*  ww  w  . j a v  a 2 s  . c o m*/
    View view = inflater.inflate(R.layout.setting, container, false);
    restaurant_icon = (ImageView) view.findViewById(R.id.restaurant_icon);
    tv_restaurant_name = (TextView) view.findViewById(R.id.tv_restaurant_name);
    tv_owner_phone = (TextView) view.findViewById(R.id.tv_owner_phone);
    tv_owner_cardnumber = (TextView) view.findViewById(R.id.tv_owner_cardnumber);
    shopmessage = (TextView) view.findViewById(R.id.shopmessage);
    if (MyApplication.getUser().getUser().get("name") != null) {
        tv_restaurant_name.setText(MyApplication.getUser().getUser().get("name").toString());
    }
    if (MyApplication.getUser().getUser().get("phone") != null) {
        tv_owner_phone.setText(MyApplication.getUser().getUser().get("phone").toString());
    }
    if (MyApplication.getUser().getUser().get("identify") != null) {
        tv_owner_cardnumber
                .setText(getDisplayStr(MyApplication.getUser().getUser().get("identify").toString()));
    }
    RelativeLayout about_us_layout = (RelativeLayout) view.findViewById(R.id.about_us_layout);
    about_us_layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(getActivity(), FeedBackActivity.class);
            startActivity(intent);
        }
    });
    RelativeLayout locationUpdate = (RelativeLayout) view.findViewById(R.id.location);
    locationUpdate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(getActivity(), LocationActivity.class);
            startActivity(intent);
        }
    });
    RelativeLayout app_recommend_layout = (RelativeLayout) view.findViewById(R.id.app_recommend_layout);
    app_recommend_layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(getActivity(), HelpActivity.class);
            startActivity(intent);
        }
    });
    RelativeLayout app_password_layout = (RelativeLayout) view.findViewById(R.id.app_password_layout);
    app_password_layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setClass(getActivity(), PhoneVerifyActivity.class);
            startActivity(intent);
        }
    });
    TextView settings_logout = (TextView) view.findViewById(R.id.settings_logout);
    settings_logout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            new AlertDialog.Builder(getActivity()).setTitle("??").setMessage("")
                    .setPositiveButton("", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            clearUser();
                            Intent intent = new Intent(getActivity(), LoginActivity.class);
                            startActivity(intent);
                            getActivity().finish();
                        }
                    }).setNegativeButton("?", null).show();
        }
    });
    LinearLayout restaurant_info_container = (LinearLayout) view.findViewById(R.id.restaurant_info_container);
    restaurant_info_container.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            /*startActivity(new Intent(getActivity(), UserModifyActivity.class));*/
            startActivity(new Intent(getActivity(), UserUpdateActivity.class));
        }
    });

    if (hashMap.get("shopmessage") != null) {
        shopmessage.setText(hashMap.get("shopmessage").toString());
    }
    LinearLayout shopmessage_layout = (LinearLayout) view.findViewById(R.id.shopmessage_layout);
    shopmessage_layout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final EditText editText = new EditText(getActivity());
            editText.setText(hashMap.get("shopmessage").toString());
            new AlertDialog.Builder(getActivity()).setTitle("?").setView(editText)
                    .setPositiveButton("", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String text = editText.getText().toString().trim();
                            shopmessage.setText(text);
                            hashMap.put("shopmessage", text);
                            updateUser(hashMap);
                        }
                    }).setNegativeButton("?", null).show();
        }
    });
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            downloadBitmap(UserModifyActivity.URL
                    + MyApplication.getUser().getUser().get("shopphoto").toString().replaceAll("\\\\", "/"));

        }
    }

    );
    thread.start();

    /*  SettingsItemView settings_connect_manager= (SettingsItemView) view.findViewById(R.id.settings_connect_manager);
    settings_connect_manager.setOnSettingClickListener(new SettingsItemView.settingClickListener() {
    @Override
    public void rightClick() {
        Toast.makeText(getActivity(), "a", Toast.LENGTH_SHORT).show();
    }
    });*/
    return view;

}

From source file:cn.wander.Utils.views.pageindicator.TabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    RelativeLayout tablayout = (RelativeLayout) View.inflate(getContext(), R.layout.tab_item_layout, null);

    final TextView tabView = (TextView) tablayout.findViewById(R.id.tab_item_title);
    tabView.setTag(index);/* w  ww  .  j  av  a  2s . c o  m*/
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setTextSize(TypedValue.COMPLEX_UNIT_PX, 19);
    tabView.setText(text);
    tabView.setTextColor(getResources().getColor(R.color.kw_common_cl_white));
    if (iconResId != 0) {
        //             tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
        ImageView iconView = (ImageView) tablayout.findViewById(R.id.tab_item_icon);
        iconView.setImageResource(iconResId);
        iconView.setVisibility(View.VISIBLE);
    }

    mTabLayout.addView(tablayout, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}