Java 使用网格视图在适配器中添加按钮阵列

Java 使用网格视图在适配器中添加按钮阵列,java,android,Java,Android,我正在尝试在网格视图适配器中添加按钮数组。请帮我运行这个程序 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);

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

 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);
for(int index=0;index
您需要扩展ArrayAdapter类并重写getView(),以返回每个项目所需的视图类型,在本例中是一个按钮。然后,您可以尝试或使用不带类型参数的类型


非常感谢。你能给我举一个简单的例子吗?这将是非常有益的。。。和在getView()中返回按钮[i];这个怎么了?您需要指定您实际遇到的问题。