I want to display country flags with respect to phone-numbers in my contact lists like rebtel(Screen shot shown below).
-
Simple solution : image name should be of country name :) now compare text with image name and display that map. – Lucifer Mar 28 '14 at 12:39
-
Why is it down voted with out reason. Let me know the reason before down voting – Gangadhar Nimballi Mar 28 '14 at 12:39
-
@Kedarnath. Some one did it with out any explanation. – Gangadhar Nimballi Mar 28 '14 at 12:53
-
1we live in democracy. Different people, different thinking, concentrate on the answer, not on the downvotes :) – Lucifer Mar 28 '14 at 12:54
-
Yes, I am not worrying about down voting. But he should explain reason. Okay Thank you – Gangadhar Nimballi Mar 28 '14 at 12:56
-
@Kedarnath's solution is much easy to implement. I'd do the same way – Dhaval Mar 28 '14 at 13:08
3 Answers
Parse the phone number and get the international prefix, then you can use Wikipedia: List_of_country_calling_codes to get the country. You can implement a Map with key being the international prefix and key the country name.

- 25,822
- 8
- 77
- 77
-
I am getting international prefix with http://stackoverflow.com/questions/16809508/extract-code-country-from-phone-number-libphonenumber/16835306#16835306 – Gangadhar Nimballi Apr 01 '14 at 10:09
Here I am giving you the logic part,
You can get the ISD code and flag image from this link http://en.wikipedia.org/wiki/List_of_country_calling_codes#Alphabetical_listing_by_country_or_region
You need to make two Array variables,
String [] countryCode = new String { "+91","+92", ... };
int [] country = new int { R.drawable.91.png, R.drawable.92.png,.... };
// Considering here 91.png is india's map
Now get the phone number from contact list , suppose you have +91987654321. So remove first + sign and compare 91 to all the resources images. When match found, put that image with the contact.

- 29,392
- 25
- 90
- 143
-
Thank you kedarnath for your answer, but jabaldonedo is very useful to me – Gangadhar Nimballi Apr 01 '14 at 10:11
You can use this library for your Requirement.
Go to detail you can show country flag and country code with use of this.

- 1,755
- 19
- 39