使用网格视图在适配器中添加按钮数组

时间:2017-06-30 01:14:34

标签: java android

我正在尝试在网格视图适配器中添加Buttons数组。请帮我运行这个程序。

 for (int index = 0; index < Item.length; index++) {
        myButton[index] = new Button(this); //initialize the button here
        myButton[index].setText(Item[index]);
        myButton[index].setWidth(120);
        myButton[index].setHeight(120);
        myButton[index].setId(index);
        //myButton[index].setTag(index);
       // scrViewButLay.addView(myButton[index]);
        myButton[index].setOnClickListener(getOnClickDoSomething(myButton[index]));
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myButton);

1 个答案:

答案 0 :(得分:0)

您需要扩展ArrayAdapter类并覆盖getView()以返回每个项目所需的视图类型,在这种情况下为按钮。然后,您可以尝试或使用没有类型参数的类型。

https://developer.android.com/guide/topics/ui/declaring-layout.html#AdapterViews

相关问题