I want to display a value stored in my ArrayList in my TextView so when the application is run the name appears in the TextView alongside other details.
I can read the values from the ArrayList and they display in the logcat. They also display on a ListView but I cant get them to display on the TextView.
private ArrayList<Country> countries; private ArrayList<Country> countries; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lvCountries = findViewById(R.id.main_activity_lv_countries); tvDetails = findViewById(R.id.activity_country_details); lvCountries.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //create an intent for the FlagDisplayActivity Intent intentBundle = new Intent(MainActivity.this, FlagDisplayActivity.class); Bundle bundleName = new Bundle(); //put arg2 as an extra in the intent. arg2 represents the item clicked on //e.g arg2 will be 0 if the first item was clicked intentBundle.putExtra(countries.get(position).getName(), countries.get(position).getFlagImageResourceId()); //start the activity startActivityForResult(intentBundle, DELETE_REQUEST); } }); countries = new ArrayList<>(); countries.add(new Country("Australia", 100, "Canberra", "English", "Dollars", R.drawable.australia)); countries.add(new Country("China", 5771876, "Beijing", "Chinese", "Renminbi", R.drawable.china)); countries.add(new Country("Germany", 126860301, "Berlin", "German", "Euros", R.drawable.germany)); countries.add(new Country("India", 60550075, "New Delhi", "Indian", "Rupees", R.drawable.india)); countries.add(new Country("UK", 100, "London", "English", "GBP", R.drawable.uk)); for (int i = 0; i < countries.size(); i++) { Log.d(TAG, "onCreate: name: " + countries.get(i).getName() + " Population: " + countries.get(i).getPopulation()); } //Create a String ArrayList to store the country names ArrayList<String> countryNames = new ArrayList<>(); //For every Country object in the countries ArrayList for (Country country : countries) { //Add the name of the country to the String ArrayList countryNames.add(country.getName() + " " + country.getPopulation() + " " + country.getCapitalCity() + " " + country.getLanguage() + " " + country.getCurrency() + " " + country.getFlagImageResourceId()); } //Create an ArrayAdapter using the countryNames String ArrayList ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, countryNames); //Set the adapter on the ListView lvCountries.setAdapter(adapter); } Information does not display in the TextView.