Articles → ANDROID → Arrayadapter In Android
Arrayadapter In Android
What Is Adapterview And Adapter?
- Adapterview is a view group that displays data loaded in adapter.
- Adapter is a bridge between a view and a data source.
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);
}
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);