spinner_country.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Country country = (Country) parent.getSelectedItem(); Toast.makeText(context, "Country ID: "+country.getId()+", Country Name : "+country.getName(), Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<?> parent) { } });
private Record createRecord(final Country country) { if (country == null) { return null; } final Map<String, Object> values = new HashMap<>(2); values.put(CitySchema.COUNTRY_NAME.getFieldName(), country.getName()); values.put(CitySchema.COUNTRY_ISO.getFieldName(), country.getIsoCode()); return new MapRecord(CitySchema.COUNTRY_SCHEMA, values); }
i++; attrs.put(new StringBuilder(ipAttributeName).append(".geo.country").toString(), response.getCountry().getName()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.country.isocode").toString(), response.getCountry().getIsoCode()); attrs.put(new StringBuilder(ipAttributeName).append(".geo.postalcode").toString(), response.getPostal().getCode());
@Override public int compareTo(Country anotherCountry) { return anotherCountry.getName().compareTo(this.name); }
RealmResults<Country> results1 = myRealm.where(Country.class).findAll(); for(Country c:results1) { Log.d("results1", c.getName()); }
countryQuery.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for (DataSnapshot countrySnapshot: dataSnapshot.getChildren()) { Country country = countrySnapshot.getValue(Country.class); assertEquals(TestUtilities.TEST_COUNTRY_ALGERIA, country.getName()); //get country key String countryKey = countrySnapshot.getKey(); } } @Override public void onCancelled(DatabaseError databaseError) { fail("Failed to get country: " + databaseError.getMessage()); } });
listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Country country = (Country) listView.getAdapter().getItem(position); String s = (String)(country.getName()); Intent i = new Intent(SecondScreenActivity.this, ThirdScreenActivity.class); i.putExtra("position", s); startActivity(i); } });
List<Country> countries = new ArrayList<>(); //when you want to reference/print those: for (Country c : countries) { System.out.println(String.format("%s, %d medals(s)", c.getName(), c.getMedals())); }
@Override public String getValue(CityResponse response) { return response.getCountry().getName(); } },
private GeoInfo _getGeoInfo(String ipAddress) { GeoInfo geoInfo = new GeoInfo(); if (ipAddress == null) { return geoInfo; } try{ InetAddress inetAddress = InetAddress.getByName(ipAddress); CityResponse response = reader.city(inetAddress); Country country = response.getCountry(); Continent continent = response.getContinent(); City city = response.getCity(); Postal postal = response.getPostal(); Location location = response.getLocation(); Subdivision subdivision = response.getMostSpecificSubdivision(); geoInfo.setRegion(subdivision.getName()); geoInfo.setCountryIsoCode(country.getIsoCode()); geoInfo.setCountry(country.getName()); geoInfo.setContinent(continent.getCode()); geoInfo.setCity(city.getName()); geoInfo.setPostalCode(postal.getCode()); geoInfo.setLatitude(location.getLatitude()); geoInfo.setLongitude(location.getLongitude()); return geoInfo; } catch(Exception ex){ return null; } }
public void onItemClick(AdapterView<?> l, View v, int position, long id) { Country country = (Country) ((CustomAdapter ) l.getAdapter()).getItem(position); Intent intent = new Intent(this, ListItemDetail.class); intent.putExtra("name", country.getName()); intent.putExtra("iso_code", country.getIso_code()); intent.putExtra("flag", country.getFlag()); startActivity(intent); }
// This is where your service layer starts. It gets as a param the Country object GenericDaoDB gDaoDB = new GenericDaoDB(); try{ List resultList = gDaoDB.list(country); System.out.println("=========Result Print=============="); for(int i=0; i<resultList.size();i++){ Country resultCountry = (Country)resultList.get(i); System.out.println("Name:"+ resultCountry.getName()+" Country Code:"+resultCountry.getCountryCode()); } }catch(BasisException e){ e.printStackTrace(); }
for (Country country : countries) { System.out.println("Country:"); System.out.println("Name: " + country.getName() + " Population: " + country.getPopulation() + " Median Age: " + country.getMedianAge()); }
for (Country country : countries) { System.out.println("Name: " + country.getName() + " Population: " + country.getPopulation() + " Median Age: " + country.getMedianAge()); }
public class CountryMain { public static void main(String[] args) { ReadCountryDB rcdb = new ReadCountryDB(); List<Country> countries = rcdb.getCountries(); for(int i=0; i<coutries.size; i++){ Country firstCountry = countries.get(i); System.out.println("First country:"); System.out.println("Name: " + firstCountry.getName() + " Population: " + firstCountry.getPopulation() + " Median Age: " + firstCountry.getMedianAge()); } } }
String ip = 85.64.225.159; int caching1 = IP2Country.NO_CACHE; // Straight on file, Fastest startup, slowest queries int caching2 = IP2Country.MEMORY_MAPPED; // Memory mapped file, fast startup, fast queries. int caching3 = IP2Country.MEMORY_CACHE; // load file into memory, slowerst startup, fastest queries IP2Country ip2c = new IP2Country(caching1); Country c = ip2c.getCountry(ip); if (c == null) { System.out.println("UNKNOWN"); } else { // will output IL ISR ISRAEL System.out.println(c.get2cStr() + " " + c.get3cStr() + " " + c.getName()); }
//Populate few country objects where Country class stores name of country in field name. List<Country> countries = new ArrayList<>(); countries.add(new Country("India")); countries.add(new Country("USA")); countries.add(new Country("Japan")); // Iterate over list String[] countryArray = new String[countries.size()]; int index = 0; for (Country country : countries) { countryArray[index] = country.getName(); index++; } // Java 8 has option of streams to get same size array String[] stringArrayUsingStream = countries.stream().map(c->c.getName()).toArray(String[]::new);