Articles → ANDROID → Arrayadapter In Android

Arrayadapter In Android






What Is Adapterview And Adapter?


  1. Adapterview is a view group that displays data loaded in adapter.
  2. Adapter is a bridge between a view and a data source.
Picture showing how data is retrieved from array adapter
Click to Enlarge


What Is An Arrayadapter?










<ListView    
      android:layout_width="match_parent"    
      android:layout_height="match_parent" 
      android:id="@+id/listview" />




@Override
protected void onCreate(Bundle savedInstanceState) 
{    
    super.onCreate(savedInstanceState);    
    setContentView(R.layout.activity_main);    
    
    String fruitlist[] = {"apple","banana","orange","cherry"};    
    ArrayAdapter<String> itemsAdapter =  new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, fruitlist);    
    ListView listView = (ListView) findViewById(R.id.listview);    
    listView.setAdapter(itemsAdapter);
}




Picture showing the output of array adapter
Click to Enlarge


Creating Array From Resource File






<resources>    
        <string-array name="sample_array">        
                <item>Banana</item>        
                <item>Apple</item>        
                <item>Orange</item>    
        </string-array>
</resources>




String fruitlist[] = getResources().getStringArray(R.array.sample_array);



Posted By  -  Karan Gupta
 
Posted On  -  Thursday, October 31, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250