There is an activity in which the orders are displayed in the ListView, in each order there is a field: a phone number, how can you make this number a link directly in the ListView, when you click on it, the number would be dialed?
- oneHow to make more than one TextView in a ListView cell - pavlofff
3 answers
1) We register in the manifest: <uses-permission android:name="android.permission.CALL_PHONE" />
2) Code for the call
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + yourArrayList.getPosition(position).getPhoneNumber())); startActivity(intent); 3) The above is an example for a list with objects. If you have each element this is a single text field with all the info, then you should redistribute it then. Well, or as a maximum play with subString
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView" android:autoLink="phone" /> This code will help you, namely the android:autoLink="phone" flag android:autoLink="phone" It sets the parameter that the phone can be in this TextView and when it is found it will be highlighted in color and will be clickable if it’s buggy, then try to split the text into several TextView and add android:autoLink="phone" only to the one in which the phone number will be cleanly written. It is also worth noting that this flag may not work and the phone may not be clickable if there is an unknown phone format, so the phones must be of an adequate format, not fffapoga and something like that
- and if I render the number in a separate TextView, but in my ListView, how can one item be a TextView with a number and a TextView with the rest of the order information? - Kirill Stoianov
- @KirillStoianov I wrote about this above, you can do so, just add a flag to the TextView, which will contain a phone number - BORSHEVIK
The most primitive way is to place the number in a separate TextView with a special style (underline and blue as a link), hang OnClickListener on it, and then work with TelephoneManager (or something like that). Check out Alexey Goloshchapov’s book Google Android Creating an App for Smartphones and Tablet PCs.
- but something like the tag "tel: //" is this? Or is it only for iOS? - Kirill Stoianov
- oneGoloshchapov page 565 (2013 book of the edition). Quote "The Extr parameter itself for an intent object is not just a phone number, but a URI object, has the following format tel: subscriber_number ...." I will not write the whole code, everything is very primitive. It is possible to carry out this challenge in two lines - Djangorussia
- I found it in the network only for 2015 but I did not find in the content what I need! Can you share a link to the book in 2013, or suggest at least what you need to look for in the content? - Kirill Stoianov
- oneExample code (initiates an outgoing call): String pnoneNum = "5554"; Uri uri = Uri.parse ("tel:" + phoneNum); Intent intent = new Intent (intent.ACTION_DIAL, uri); startActivity (intent); Don't forget to add to the manifest file android.permission.CALL_PHONE - Djangorussia
- Chapter "Handling phone calls", sub. chapter: "Calling a phone subscriber from the app" - Djangorussia
