0

First I have build a simple android application which had only five optios to select. For this purpose I used five Buttons on main Activity. Now I have more than twenty buttons in a ScrollView to select. What is the best way to represent this kind of application (using buttons in a ScrollView? using TabHost? or with some other widget?)

The app look like this now:

enter image description here

Ferguson
  • 527
  • 1
  • 11
  • 29

2 Answers2

2

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.
Ahmed I. Elsayed
  • 2,013
  • 2
  • 17
  • 30
1

Use grid view. it will be easy to show multiple buttons on screen using grid view.

Tanuj Yadav
  • 1,259
  • 13
  • 21