3

So Ive currently made a working app that when the user puts in an employees name and searches it searches my sql database and returns with a name, phone number, id and address all in a list so that each result is kinda separated from the next. Im trying to make the phone number auto link as a phone number so that the user can click on it and it will call it but Im unsure of how to do this. Yes I have followed and looked at the other tutorials for that on this site and haven't been able to make it work. hoping you guys can help me out. For starters, yes I have added the permission to the manifest.

Here is the xml layout for the textview I wish to make clickable

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Phone Number"
    android:id="@+id/textType"
    android:layout_marginLeft="5dp"
    android:layout_below="@id/textSize"
    android:textColor="#666"
    android:clickable="true" />

And here the java that setups up how the number will be displayed. Not sure if this is needed or even helps.

myHolder.textType.setText("Mobile Phone# " + current.Phonenum);
guipivoto
  • 18,327
  • 9
  • 60
  • 75
WChampion
  • 75
  • 1
  • 9

2 Answers2

6

Try adding the android:autoLink="phone" attribute, so your code should look like this:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="123 456 7890"
    android:id="@+id/textType"
    android:layout_marginLeft="5dp"
    android:layout_below="@id/textSize"
    android:autoLink="phone"
    android:textColor="#666"
    android:clickable="true"
/>
Pang
  • 9,564
  • 146
  • 81
  • 122
ishmaelMakitla
  • 3,784
  • 3
  • 26
  • 32
-2

On the TextView in the xml add:

 android:inputType="phone"
metasim
  • 4,793
  • 3
  • 46
  • 70
Gil Snovsky
  • 210
  • 2
  • 6
  • when i go to test it it just tells me that i clicked an object(which i put in there) but it doesn't start a call (using the emulator) does the relative layout for the list need to be set to android:clickable="true"? i currently have it set to false because i though that meant users couldn't click on everything then and could only click on what is set to true? Sorry if im confusing you. About a week into my coding expierence – WChampion Jun 03 '16 at 18:27
  • yes set to true, try to change to textview to edittext – Gil Snovsky Jun 03 '16 at 18:37