1. Check out our companion app, Forums for Android! Download from Google Play

ArrayAdapter question

Discussion in 'Application Development' started by LeonR, Mar 2, 2010.

  1. LeonR

    LeonR Member
    Thread Starter
    15

    Feb 22, 2010
    18
    0
    15
    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? :thinking:


    Thanks!! :)
     

    Advertisement

  2. LeonR

    LeonR Member
    Thread Starter
    15

    Feb 22, 2010
    18
    0
    15
    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?
    513

    Nov 29, 2009
    7,978
    3,606
    513
    Android App Developer
    NY
    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...