How to click or tap on a TextView text

后端 未结 8 1696
無奈伤痛
無奈伤痛 2020-11-27 09:52

I know this is so easy (doh...) but I am looking for a way to run a method on tapping or clicking a TextView line of text in an Android App.

I keep thinking about bu

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 10:23

    from inside an activity that calls a layout and a textview, this click listener works:

    setContentView(R.layout.your_layout);
    TextView tvGmail = (TextView) findViewById(R.id.tvGmail);
    String TAG = "yourLogCatTag";
    tvGmail.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View viewIn) {
                    try {
                        Log.d(TAG,"GMAIL account selected");
                    } catch (Exception except) {
                        Log.e(TAG,"Ooops GMAIL account selection problem "+except.getMessage());
                    }
                }
            });
    

    the text view is declared like this (default wizard):

            
    

    and in the strings.xml file

    Google ID (Gmail)
    

提交回复
热议问题