Grid View
or List View
or Recycler View
the Adapter automatically will add buttons with the names you want, something that I did for my upcoming app.
I made a java class called data
which has 'data` for my app.
it has an array of images for my GridView.
SO:
- Make a class called data
- Add a
public final static String[] myArray
array of your names, or data
- Now, whenever you want to access them, use data.myArray
- If you want to access one item ,use data.myArray[itemIndex]
- Don't forget, indexes are zero based, not 1
- Put your button inside a
viewHolder
class
- find the id of the button in the
getView
if convertView
is null
& set the holder as a tag
NOTE : after finding the ID of the button, just leave it don't do anything or edit the text, continue reading please.
- Use that array with your custom adapter
as
gridView.setAdapter(new myCustomAdapter(parameter1, parameter2,data.myArray);
use this , I just made it yesterday, added array of buttons feature now. You can just learn it or use it or commit changes.
NOTE :
- You can make an array of listeners just like any primitive data type,
View.OnClickListener[]
and name it, initialize it.