how to make text view clickable in android?

前端 未结 11 1534
轮回少年
轮回少年 2020-12-01 18:04

is it possible in android to make text view clickable if yes then how ??and if not then what will be the way for make a label clickable??i want to implement a call activit

相关标签:
11条回答
  • 2020-12-01 18:19
    textView.setOnClickListener(new View.OnClickListener());
    

    Have you tried this?

    0 讨论(0)
  • 2020-12-01 18:20

    you can set a onclick listener to the texview like button.infact button inherits the properties from textview.

    0 讨论(0)
  • 2020-12-01 18:22

    Simply try this one:-

    Implement View.OnClickListener, then simply apply switch case and define the id of your text view in the case and pass the intent.

    example:-

         @Override
     public void onClick(View v) {
        //TODO Auto-generated method stub
    
       switch (v.getId()) {
    case R.id.textView:
        startActivity(new Intent(this,CalledClass.class));
    
        break;
    
    default:
        break;
    }
    

    //here textView is id for the textView I chose.

    0 讨论(0)
  • 2020-12-01 18:35

    TextView is also derived of View like- EditText,ListView etc.,so we can use

    textView.setOnClickListener(new View.OnClickListener());
    
    0 讨论(0)
  • 2020-12-01 18:37

    First in your java file cast your TextView by xml id

    TextView tv = (TextView)findViewById(R.Id.textView1);
    

    then,

    tv.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
          // TODO Auto-generated method stub
       }
    });
    
    0 讨论(0)
  • 2020-12-01 18:37

    Though it was long ago when you asked your question. But I think that the right thing to attain what you wanted is to set TextView xml attribute android:autoLink. For example:

    <TextView 
        ...
        android:autoLink="phone" />
    
    0 讨论(0)
提交回复
热议问题