Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can download the project from <a href="https://dl.dropboxusercontent.com/u/108355121/CountriestListProject/CountriesWithFlags.rar">here</a>.</p> <p>We need files with codes described below.</p> <p>class <strong>MainActivity</strong></p> <pre><code>package com.example.countrieswithflags; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.ListView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String[] recourseList=this.getResources().getStringArray(R.array.CountryCodes); final ListView listview = (ListView) findViewById(R.id.listView); listview.setAdapter(new CountriesListAdapter(this, recourseList)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>We need adapter for list </p> <p><strong>CountriesListAdapter</strong></p> <pre><code>package com.example.countrieswithflags; import java.util.Locale; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; public class CountriesListAdapter extends ArrayAdapter&lt;String&gt; { private final Context context; private final String[] values; public CountriesListAdapter(Context context, String[] values) { super(context, R.layout.country_list_item, values); this.context = context; this.values = values; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.country_list_item, parent, false); TextView textView = (TextView) rowView.findViewById(R.id.txtViewCountryName); ImageView imageView = (ImageView) rowView.findViewById(R.id.imgViewFlag); String[] g=values[position].split(","); textView.setText(GetCountryZipCode(g[1]).trim()); String pngName = g[1].trim().toLowerCase(); imageView.setImageResource(context.getResources().getIdentifier("drawable/" + pngName, null, context.getPackageName())); return rowView; } private String GetCountryZipCode(String ssid){ Locale loc = new Locale("", ssid); return loc.getDisplayCountry().trim(); } } </code></pre> <p>Our <strong>strings.xml</strong> will have this lines </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string name="app_name"&gt;Countries With Flags&lt;/string&gt; &lt;string name="action_settings"&gt;Settings&lt;/string&gt; &lt;string name="hello_world"&gt;Hello world!&lt;/string&gt; &lt;string-array name="CountryCodes" &gt; &lt;item&gt;93,AF&lt;/item&gt; &lt;item&gt;355,AL&lt;/item&gt; &lt;item&gt;213,DZ&lt;/item&gt; &lt;item&gt;376,AD&lt;/item&gt; &lt;item&gt;244,AO&lt;/item&gt; &lt;item&gt;54,AR&lt;/item&gt; &lt;item&gt;374,AM&lt;/item&gt; &lt;item&gt;297,AW&lt;/item&gt; &lt;item&gt;61,AU&lt;/item&gt; &lt;item&gt;43,AT&lt;/item&gt; &lt;item&gt;994,AZ&lt;/item&gt; &lt;item&gt;973,BH&lt;/item&gt; &lt;item&gt;880,BD&lt;/item&gt; &lt;item&gt;375,BY&lt;/item&gt; &lt;item&gt;32,BE&lt;/item&gt; &lt;item&gt;501,BZ&lt;/item&gt; &lt;item&gt;229,BJ&lt;/item&gt; &lt;item&gt;975,BT&lt;/item&gt; &lt;item&gt;591,BO&lt;/item&gt; &lt;item&gt;387,BA&lt;/item&gt; &lt;item&gt;267,BW&lt;/item&gt; &lt;item&gt;55,BR&lt;/item&gt; &lt;item&gt;673,BN&lt;/item&gt; &lt;item&gt;359,BG&lt;/item&gt; &lt;item&gt;226,BF&lt;/item&gt; &lt;item&gt;95,MM&lt;/item&gt; &lt;item&gt;257,BI&lt;/item&gt; &lt;item&gt;855,KH&lt;/item&gt; &lt;item&gt;237,CM&lt;/item&gt; &lt;item&gt;1,CA&lt;/item&gt; &lt;item&gt;238,CV&lt;/item&gt; &lt;item&gt;236,CF&lt;/item&gt; &lt;item&gt;235,TD&lt;/item&gt; &lt;item&gt;56,CL&lt;/item&gt; &lt;item&gt;86,CN&lt;/item&gt; &lt;item&gt;61,CX&lt;/item&gt; &lt;item&gt;61,CC&lt;/item&gt; &lt;item&gt;57,CO&lt;/item&gt; &lt;item&gt;269,KM&lt;/item&gt; &lt;item&gt;242,CG&lt;/item&gt; &lt;item&gt;243,CD&lt;/item&gt; &lt;item&gt;682,CK&lt;/item&gt; &lt;item&gt;506,CR&lt;/item&gt; &lt;item&gt;385,HR&lt;/item&gt; &lt;item&gt;53,CU&lt;/item&gt; &lt;item&gt;357,CY&lt;/item&gt; &lt;item&gt;420,CZ&lt;/item&gt; &lt;item&gt;45,DK&lt;/item&gt; &lt;item&gt;253,DJ&lt;/item&gt; &lt;item&gt;670,TL&lt;/item&gt; &lt;item&gt;593,EC&lt;/item&gt; &lt;item&gt;20,EG&lt;/item&gt; &lt;item&gt;503,SV&lt;/item&gt; &lt;item&gt;240,GQ&lt;/item&gt; &lt;item&gt;291,ER&lt;/item&gt; &lt;item&gt;372,EE&lt;/item&gt; &lt;item&gt;251,ET&lt;/item&gt; &lt;item&gt;500,FK&lt;/item&gt; &lt;item&gt;298,FO&lt;/item&gt; &lt;item&gt;679,FJ&lt;/item&gt; &lt;item&gt;358,FI&lt;/item&gt; &lt;item&gt;33,FR&lt;/item&gt; &lt;item&gt;689,PF&lt;/item&gt; &lt;item&gt;241,GA&lt;/item&gt; &lt;item&gt;220,GM&lt;/item&gt; &lt;item&gt;995,GE&lt;/item&gt; &lt;item&gt;49,DE&lt;/item&gt; &lt;item&gt;233,GH&lt;/item&gt; &lt;item&gt;350,GI&lt;/item&gt; &lt;item&gt;30,GR&lt;/item&gt; &lt;item&gt;299,GL&lt;/item&gt; &lt;item&gt;502,GT&lt;/item&gt; &lt;item&gt;224,GN&lt;/item&gt; &lt;item&gt;245,GW&lt;/item&gt; &lt;item&gt;592,GY&lt;/item&gt; &lt;item&gt;509,HT&lt;/item&gt; &lt;item&gt;504,HN&lt;/item&gt; &lt;item&gt;852,HK&lt;/item&gt; &lt;item&gt;36,HU&lt;/item&gt; &lt;item&gt;91,IN&lt;/item&gt; &lt;item&gt;62,ID&lt;/item&gt; &lt;item&gt;98,IR&lt;/item&gt; &lt;item&gt;964,IQ&lt;/item&gt; &lt;item&gt;353,IE&lt;/item&gt; &lt;item&gt;44,IM&lt;/item&gt; &lt;item&gt;972,IL&lt;/item&gt; &lt;item&gt;39,IT&lt;/item&gt; &lt;item&gt;225,CI&lt;/item&gt; &lt;item&gt;81,JP&lt;/item&gt; &lt;item&gt;962,JO&lt;/item&gt; &lt;item&gt;7,KZ&lt;/item&gt; &lt;item&gt;254,KE&lt;/item&gt; &lt;item&gt;686,KI&lt;/item&gt; &lt;item&gt;965,KW&lt;/item&gt; &lt;item&gt;996,KG&lt;/item&gt; &lt;item&gt;856,LA&lt;/item&gt; &lt;item&gt;371,LV&lt;/item&gt; &lt;item&gt;961,LB&lt;/item&gt; &lt;item&gt;266,LS&lt;/item&gt; &lt;item&gt;231,LR&lt;/item&gt; &lt;item&gt;218,LY&lt;/item&gt; &lt;item&gt;423,LI&lt;/item&gt; &lt;item&gt;370,LT&lt;/item&gt; &lt;item&gt;352,LU&lt;/item&gt; &lt;item&gt;853,MO&lt;/item&gt; &lt;item&gt;389,MK&lt;/item&gt; &lt;item&gt;261,MG&lt;/item&gt; &lt;item&gt;265,MW&lt;/item&gt; &lt;item&gt;60,MY&lt;/item&gt; &lt;item&gt;960,MV&lt;/item&gt; &lt;item&gt;223,ML&lt;/item&gt; &lt;item&gt;356,MT&lt;/item&gt; &lt;item&gt;692,MH&lt;/item&gt; &lt;item&gt;222,MR&lt;/item&gt; &lt;item&gt;230,MU&lt;/item&gt; &lt;item&gt;262,YT&lt;/item&gt; &lt;item&gt;52,MX&lt;/item&gt; &lt;item&gt;691,FM&lt;/item&gt; &lt;item&gt;373,MD&lt;/item&gt; &lt;item&gt;377,MC&lt;/item&gt; &lt;item&gt;976,MN&lt;/item&gt; &lt;item&gt;382,ME&lt;/item&gt; &lt;item&gt;212,MA&lt;/item&gt; &lt;item&gt;258,MZ&lt;/item&gt; &lt;item&gt;264,NA&lt;/item&gt; &lt;item&gt;674,NR&lt;/item&gt; &lt;item&gt;977,NP&lt;/item&gt; &lt;item&gt;31,NL&lt;/item&gt; &lt;item&gt;599,AN&lt;/item&gt; &lt;item&gt;687,NC&lt;/item&gt; &lt;item&gt;64,NZ&lt;/item&gt; &lt;item&gt;505,NI&lt;/item&gt; &lt;item&gt;227,NE&lt;/item&gt; &lt;item&gt;234,NG&lt;/item&gt; &lt;item&gt;683,NU&lt;/item&gt; &lt;item&gt;850,KP&lt;/item&gt; &lt;item&gt;47,NO&lt;/item&gt; &lt;item&gt;968,OM&lt;/item&gt; &lt;item&gt;92,PK&lt;/item&gt; &lt;item&gt;680,PW&lt;/item&gt; &lt;item&gt;507,PA&lt;/item&gt; &lt;item&gt;675,PG&lt;/item&gt; &lt;item&gt;595,PY&lt;/item&gt; &lt;item&gt;51,PE&lt;/item&gt; &lt;item&gt;63,PH&lt;/item&gt; &lt;item&gt;870,PN&lt;/item&gt; &lt;item&gt;48,PL&lt;/item&gt; &lt;item&gt;351,PT&lt;/item&gt; &lt;item&gt;1,PR&lt;/item&gt; &lt;item&gt;974,QA&lt;/item&gt; &lt;item&gt;40,RO&lt;/item&gt; &lt;item&gt;7,RU&lt;/item&gt; &lt;item&gt;250,RW&lt;/item&gt; &lt;item&gt;590,BL&lt;/item&gt; &lt;item&gt;685,WS&lt;/item&gt; &lt;item&gt;378,SM&lt;/item&gt; &lt;item&gt;239,ST&lt;/item&gt; &lt;item&gt;966,SA&lt;/item&gt; &lt;item&gt;221,SN&lt;/item&gt; &lt;item&gt;381,RS&lt;/item&gt; &lt;item&gt;248,SC&lt;/item&gt; &lt;item&gt;232,SL&lt;/item&gt; &lt;item&gt;65,SG&lt;/item&gt; &lt;item&gt;421,SK&lt;/item&gt; &lt;item&gt;386,SI&lt;/item&gt; &lt;item&gt;677,SB&lt;/item&gt; &lt;item&gt;252,SO&lt;/item&gt; &lt;item&gt;27,ZA&lt;/item&gt; &lt;item&gt;82,KR&lt;/item&gt; &lt;item&gt;34,ES&lt;/item&gt; &lt;item&gt;94,LK&lt;/item&gt; &lt;item&gt;290,SH&lt;/item&gt; &lt;item&gt;508,PM&lt;/item&gt; &lt;item&gt;249,SD&lt;/item&gt; &lt;item&gt;597,SR&lt;/item&gt; &lt;item&gt;268,SZ&lt;/item&gt; &lt;item&gt;46,SE&lt;/item&gt; &lt;item&gt;41,CH&lt;/item&gt; &lt;item&gt;963,SY&lt;/item&gt; &lt;item&gt;886,TW&lt;/item&gt; &lt;item&gt;992,TJ&lt;/item&gt; &lt;item&gt;255,TZ&lt;/item&gt; &lt;item&gt;66,TH&lt;/item&gt; &lt;item&gt;228,TG&lt;/item&gt; &lt;item&gt;690,TK&lt;/item&gt; &lt;item&gt;676,TO&lt;/item&gt; &lt;item&gt;216,TN&lt;/item&gt; &lt;item&gt;90,TR&lt;/item&gt; &lt;item&gt;993,TM&lt;/item&gt; &lt;item&gt;688,TV&lt;/item&gt; &lt;item&gt;971,AE&lt;/item&gt; &lt;item&gt;256,UG&lt;/item&gt; &lt;item&gt;44,GB&lt;/item&gt; &lt;item&gt;380,UA&lt;/item&gt; &lt;item&gt;598,UY&lt;/item&gt; &lt;item&gt;1,US&lt;/item&gt; &lt;item&gt;998,UZ&lt;/item&gt; &lt;item&gt;678,VU&lt;/item&gt; &lt;item&gt;39,VA&lt;/item&gt; &lt;item&gt;58,VE&lt;/item&gt; &lt;item&gt;84,VN&lt;/item&gt; &lt;item&gt;681,WF&lt;/item&gt; &lt;item&gt;967,YE&lt;/item&gt; &lt;item&gt;260,ZM&lt;/item&gt; &lt;item&gt;263,ZW&lt;/item&gt; &lt;/string-array&gt; &lt;/resources&gt; </code></pre> <p>in layout we must have <strong>country_list_item.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;ImageView android:id="@+id/imgViewFlag" android:layout_height="11px" android:layout_width="16px" android:layout_margin="5dp" /&gt; &lt;TextView android:id="@+id/txtViewCountryName" android:layout_height="wrap_content" android:layout_width="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>and <strong>activity_main.xml</strong></p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" &gt; &lt;ListView android:id="@+id/listView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="15dp" &gt; &lt;/ListView&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>Also</strong> You can find images of flags with correct names (iso names of countries) from <a href="http://www.translatorscafe.com/cafe/ISO-3166-Country-Codes.htm">here</a>. Or You can find them in the project(link given above).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload