[英]Best way to make a layout with many buttons on Android
First I have build a simple android application which had only five optios to select. 首先,我建立了一个简单的android应用程序,只有五个选项可供选择。 For this purpose I used five Buttons on main Activity. 为此,我在主活动上使用了五个按钮。 Now I have more than twenty buttons in a ScrollView to select. 现在,在ScrollView中有二十多个按钮可供选择。 What is the best way to represent this kind of application (using buttons in a ScrollView? using TabHost? or with some other widget?) 代表这种应用程序的最佳方法是什么(使用ScrollView中的按钮?使用TabHost?还是使用其他小部件?)
The app look like this now: 该应用现在看起来像这样:
Grid View
or List View
or Recycler View
Grid View
或List View
或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. 我制作了一个名为data
的Java类,该类的应用程序具有“ data
”。 it has an array of images for my GridView. 它为我的GridView提供了一系列图像。
SO: 所以:
public final static String[] myArray
array of your names, or data 添加名称或数据的public final static String[] myArray
数组 viewHolder
class 将您的按钮放在viewHolder
类中 getView
if convertView
is null
& set the holder as a tag 如果convertView
为null
,则在getView
找到按钮的ID,并将该holder设置为标记 NOTE : after finding the ID of the button, just leave it don't do anything or edit the text, continue reading please. 注意:找到按钮的ID后,请不要进行任何操作或编辑文本,请继续阅读。
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 : 注意 :
View.OnClickListener[]
and name it, initialize it. 您可以像任何原始数据类型View.OnClickListener[]
一样View.OnClickListener[]
一个侦听器数组,并将其命名,初始化。 Use grid view
. 使用grid view
。 it will be easy to show multiple buttons on screen using grid view. 使用网格视图很容易在屏幕上显示多个按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.