我想将ImageButtons
动态文字添加到GridView
(如下所示),并设置listener
,以便用户点击其中一个不同的页面图标。按钮需要先水平填充,所以我想我需要2个循环。我已经搜索过,但我找不到一个如何做到这一点的好教程。
我打算怎么做
ArrayList<String> options = getOptions();
for(int i=0; i<options.size(); i++){
String opt = options.get(i);
if(opt.equals("Contacts")){
//Add Contacts button with image in GridView
Button btn = new Button(this);
//Set button text
//Set image
//Set listener to go to another activity
layout.addView(btn);
}else if(..){
//Add another button with image in GridView
//Set button text
//Set image
//Set listener to go to another activity
}
}
如果有人可以指导我如何在ButtonImage
中动态设置Button Text
,listener
和GridView
,我将非常感激。提前谢谢!
答案 0 :(得分:0)
- List item Create xml file and take Gridview in it and even Textview
reference it in the class/java file you wnat to use
- List item
Now when you use the grid view you will use the imageadapter and extends the base adapter
while in that you will have the getview() function where u set the image source dynamically and even set the Textview every time
我找到了一个例子,请你参考