ListView problem: rows have no content until scrolling

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

ListView problem: rows have no content until scrolling

Postby relsieg » Wed Jan 27, 2010 10:10 am

Hello everyone,

I have a (weird?) problem with ListView.
In my example I use custom rows. The interesting thing about it is: After running the app, the rows are displayed but without content.
It appears only after I scrolled down and up again.
The same thing happens when I test it on my phone (HTC Magic).

Here's the code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.android.test;
  3.  
  4.  
  5.  
  6. import java.util.ArrayList;
  7.  
  8. import java.util.List;
  9.  
  10.  
  11.  
  12. import android.R.string;
  13.  
  14. import android.app.Activity;
  15.  
  16. import android.app.ListActivity;
  17.  
  18. import android.app.ProgressDialog;
  19.  
  20. import android.content.Context;
  21.  
  22. import android.os.Bundle;
  23.  
  24. import android.util.Log;
  25.  
  26. import android.view.LayoutInflater;
  27.  
  28. import android.view.View;
  29.  
  30. import android.view.ViewGroup;
  31.  
  32. import android.widget.ArrayAdapter;
  33.  
  34. import android.widget.ListView;
  35.  
  36. import android.widget.TextView;
  37.  
  38.  
  39.  
  40. public class ComparisonView extends Activity{
  41.  
  42.    
  43.  
  44.     private ItemsAdapter adapter;
  45.  
  46.    
  47.  
  48.       static final String[] COUNTRIES = new String[] {
  49.  
  50.             "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
  51.  
  52.             "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
  53.  
  54.             "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
  55.  
  56.             "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
  57.  
  58.             "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
  59.  
  60.             "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory",
  61.  
  62.             "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
  63.  
  64.             "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  65.  
  66.             "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
  67.  
  68.             "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
  69.  
  70.             "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
  71.  
  72.             "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
  73.  
  74.             "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
  75.  
  76.             "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
  77.  
  78.             "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
  79.  
  80.             "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
  81.  
  82.             "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
  83.  
  84.             "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
  85.  
  86.             "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
  87.  
  88.             "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
  89.  
  90.             "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
  91.  
  92.             "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
  93.  
  94.             "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
  95.  
  96.             "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
  97.  
  98.             "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
  99.  
  100.             "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
  101.  
  102.             "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
  103.  
  104.             "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
  105.  
  106.             "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
  107.  
  108.             "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
  109.  
  110.             "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
  111.  
  112.             "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
  113.  
  114.             "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
  115.  
  116.             "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
  117.  
  118.             "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
  119.  
  120.             "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
  121.  
  122.             "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
  123.  
  124.             "Ukraine", "United Arab Emirates", "United Kingdom",
  125.  
  126.             "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
  127.  
  128.             "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
  129.  
  130.             "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
  131.  
  132.           };
  133.  
  134.    
  135.  
  136.     @Override
  137.  
  138.     public void onCreate(Bundle savedInstanceState) {
  139.  
  140.         super.onCreate(savedInstanceState);
  141.  
  142.         setContentView(R.layout.main);
  143.  
  144.        
  145.  
  146.          
  147.  
  148.            this.adapter = new ItemsAdapter(this, R.layout.row, this.COUNTRIES);
  149.  
  150.  
  151.  
  152.            TextView tv = (TextView)findViewById(R.id.firstText);
  153.  
  154.            tv.setText( "Anfang" );
  155.  
  156.  
  157.  
  158.            ListView lv = (ListView)findViewById(R.id.list);
  159.  
  160.            lv.setAdapter(this.adapter);
  161.  
  162.     }
  163.  
  164.  
  165.  
  166.     private class ItemsAdapter extends ArrayAdapter<String> {
  167.  
  168.  
  169.  
  170.         private String[] items;
  171.  
  172.  
  173.  
  174.         public ItemsAdapter(Context context, int textViewResourceId, String[] items) {
  175.  
  176.                 super(context, textViewResourceId, items);
  177.  
  178.                 this.items = items;
  179.  
  180.         }
  181.  
  182.  
  183.  
  184.         @Override
  185.  
  186.         public View getView(int position, View convertView, ViewGroup parent) {
  187.  
  188.                 View v = convertView;
  189.  
  190.                 if (v == null) {
  191.  
  192.                         LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  193.  
  194.                 v = vi.inflate(R.layout.row, null);
  195.  
  196.                 }
  197.  
  198.                
  199.  
  200.                 //Item it = this.items.get(position);
  201.  
  202.                 String c = this.items[position];
  203.  
  204.                 if (c != null) {
  205.  
  206.                         TextView tt = (TextView)findViewById(R.id.toptext);
  207.  
  208.                         if( tt != null ) {
  209.  
  210.                             tt.setText( c );
  211.  
  212.                         }
  213.  
  214.                 }
  215.  
  216.  
  217.  
  218.                 return v;
  219.  
  220.         }
  221.  
  222.     }
  223.  
  224.  
  225.  
  226.  
  227.  
  228. }  
  229.  
  230.  
Parsed in 0.070 seconds, using GeSHi 1.0.8.4

I also worked with the logs but didn't succeed.
Any ideas?

Thank you,
R.
relsieg
Freshman
Freshman
 
Posts: 9
Joined: Fri Jul 24, 2009 10:06 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 15 guests