GridView By using Custom ArrayAdapter
Solution 1
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.
Solution 2
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);
Related videos on Youtube
rupesh
Updated on October 09, 2022Comments
-
rupesh over 1 year
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?
-
rupesh over 10 yearsmy doubt is if i will use custom adapter that is extending Array Adapter , so only in layout file i will have to do the change from ListView to GridView. Am i right??
-
M-Wajeeh over 10 yearsYou can use same adapter for either
GridView
orListView
. So yes you just need to change in layout and as well as where you callsetAdapter()
. -
Azurespot about 9 yearsBut is it possible to load photos into a
GridView
, usingArrayAdapter
? The code you gave uses asimple_list_item_1
, which is aTextView
layout. I am trying to find a way to useArrayAdapter
but to upload images, no text. -
Adhikari Bishwash about 9 yearsYou can use custom adapter this blog mkyong.com/android/android-gridview-example explains
-
Azurespot about 9 yearsThanks, but that blog only covers simple text
String
in aGridView
. Images are a whole other thing, as I'm learning, you need a model, and to change things intoBitmap
, etc... :(