Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView By using Custom ArrayAdapter

Maybe I am asking the wrong question just for curiosity. I am creating the custom adapter by extending array adapter. Now I want to display this in GridView. I have gone through many articles and everywhere I found they are using only base adapter to display the GridView. Please guys tell me what is the logic behind this? Can we use Array adapter in place of Base Adapter?

like image 276
rupesh Avatar asked Dec 23 '13 06:12

rupesh


2 Answers

Yes we can. ArrayAdpter itself extends from BaseAdapter. May be this will clear things up http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/widget/ArrayAdapter.java#ArrayAdapter

In-fact if you are just trying to show some stuff in ListView or GridView that doesn't require any complex custom adapter then its easier to just use an ArrayAdapter. Its just an adapter backed by an array of arbitrary objects.

like image 179
M-WaJeEh Avatar answered Oct 04 '22 04:10

M-WaJeEh


You can certainly use ArrayAdapter in GridView. see this code example

gridView = (GridView) findViewById(R.id.gridView1);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, numbers);

gridView.setAdapter(adapter);

for more detail

like image 45
Adhikari Bishwash Avatar answered Oct 04 '22 04:10

Adhikari Bishwash