ArrayAdapter question


Last Updated:

  1. LeonR

    LeonR Member This Topic's Starter

    Joined:
    Feb 22, 2010
    Messages:
    18
    Likes Received:
    0
    As im new, i'm obviously trying to learn and figure everything out still..

    I'm simply trying to update a listview...

    I created ListView01 on my main.xml .

    Then using various examples, i have the following code..

    Code (Text):
    1.  
    2.  
    3. public class UItestAct extends ListActivity {
    4.     /** Called when the activity is first created. */
    5.    
    6.      static final String[] COUNTRIES = new String[] {
    7.             "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra"};
    8.    
    9.    
    10.    
    11.     @Override
    12.     public void onCreate(Bundle savedInstanceState) {
    13.         super.onCreate(savedInstanceState);
    14.  
    15.        
    16.         ListView myListView = (ListView)findViewById(R.id.ListView01);
    17.        
    18.    
    19.        
    20.        
    21.         ArrayAdapter<String> myAdaptor = new ArrayAdapter<String>(this,R.layout.main,COUNTRIES);
    22.        
    23.        
    24.         myListView.setAdapter(myAdaptor);
    25.        
    26.        
    27.         //setListAdapter(myAdaptor);
    28.        // getListView().setTextFilterEnabled(true);
    29.        
    30.       }
    31.    
    32.    
    33.    
    34.    
    35.    
    36. }
    37.  
    38.  
    39.  
    40.  


    I'm not exactly sure how to reference my main.xml layout? What am I doing wrong? :confused:


    Thanks!! :)
     

    Advertisement
  2. LeonR

    LeonR Member This Topic's Starter

    Joined:
    Feb 22, 2010
    Messages:
    18
    Likes Received:
    0
    May of fixed it now!

    Code (Text):
    1.  
    2.  
    3. public class UItestAct extends Activity {
    4.     /** Called when the activity is first created. */
    5.    
    6.      static final String[] COUNTRIES = new String[] {
    7.             "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra"};
    8.    
    9.    
    10.    
    11.     @Override
    12.     public void onCreate(Bundle savedInstanceState) {
    13.         super.onCreate(savedInstanceState);
    14.  
    15.         setContentView(R.layout.main);
    16.        
    17.         ListView myListView = (ListView)findViewById(R.id.ListView01);
    18.    
    19.        
    20.        ArrayAdapter<String> myAdaptor = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,COUNTRIES);
    21.          
    22.        
    23.         myListView.setAdapter(myAdaptor);
    24.        
    25.        
    26.        // getListView().setTextFilterEnabled(true);
    27.        
    28.       }
    29.    
    30.    
    31.    
    32.    
    33.    
    34. }
    35.  
    36.  
     
  3. alostpacket

    alostpacket Over Macho Grande? VIP Member

    Joined:
    Nov 29, 2009
    Messages:
    7,978
    Likes Received:
    3,603
    God I hate method overloading. That array adapter constructor looked so weird to me until i looked it up and realized there are like 5 different signatures for the constructor. :(
     

Share This Page

Loading...