开发者

how to make a text as selectable?

开发者 https://www.devze.com 2023-02-02 06:12 出处:网络
I have some TextViews for phone no. These are not editable. So I have made them as TextView. I want to perform click action on phone no, i.e开发者_StackOverflow中文版. on clicking phone no i have to m

I have some TextViews for phone no. These are not editable. So I have made them as TextView. I want to perform click action on phone no, i.e开发者_StackOverflow中文版. on clicking phone no i have to make a call. How to implement that? Anyone any idea?


The best way to get that functionality is to set this parameter for your TextView in which you display the phone number:

android:autoLink="phone"

Alternatively (not sure if this is a good practice though. perhaps someone could help out here), you can set it to

android:autoLink="all"

The later will detect any email addresses, website URL's, maps and convert them into relevant links on the fly.


add ClickListener to that textview

textview.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String number = "tel:"+youPhoneNo;
            Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
            startActivity(Intent.createChooser(callIntent, "Phone..."));
        }

    });
0

精彩评论

暂无评论...
验证码 换一张
取 消