无法实现方法

Cant implement method

我想实现以下方法:

public void setButtons(Button b, int h, int w){
    b.setLayoutParams(new LinearLayout.LayoutParams(w, h));
}

在我的 onCreate 方法中:

        for (int i = 0; i < buttons.length; i++){
        public void setButtons(buttons[i], widthOfButtons, widthOfButtons);
    }

但我遇到了错误,一段时间以来我一直在试图找出问题所在,但我对 java 还是个新手,我觉得这段代码只需要别人的眼睛,所以有人能告诉我怎么做吗正确实施上述方法?谢谢

编辑

添加更多代码: 下面是我初始化数组的地方:

   Button[] buttons = new Button[23];
    buttons[0] = (Button) findViewById(R.id.alef);
    buttons[1] = (Button) findViewById(R.id.beis);
    buttons[3] = (Button) findViewById(R.id.gimmel);
    buttons[4] = (Button) findViewById(R.id.daled);
    buttons[5] = (Button) findViewById(R.id.heh);
    buttons[6] = (Button) findViewById(R.id.vav);
    buttons[7] = (Button) findViewById(R.id.zayin);
    buttons[7] = (Button) findViewById(R.id.ches);
    buttons[8] = (Button) findViewById(R.id.tes);
    buttons[9] = (Button) findViewById(R.id.yud);
    buttons[10] = (Button) findViewById(R.id.chaf);
    buttons[11] = (Button) findViewById(R.id.lamed);
    buttons[12] = (Button) findViewById(R.id.mem);
    buttons[13] = (Button) findViewById(R.id.nun);
    buttons[14] = (Button) findViewById(R.id.ayin);
    buttons[15] = (Button) findViewById(R.id.peh);
    buttons[16] = (Button) findViewById(R.id.tzadi);
    buttons[17] = (Button) findViewById(R.id.kuf);
    buttons[18] = (Button) findViewById(R.id.reish);
    buttons[19] = (Button) findViewById(R.id.shin);
    buttons[20] = (Button) findViewById(R.id.taf);
    buttons[21] = (Button) findViewById(R.id.empty1);
    buttons[22] = (Button) findViewById(R.id.empty2);
    buttons[23] = (Button) findViewById(R.id.empty3);

这是我声明的完整 class 方法:

import android.widget.Button;
import android.widget.LinearLayout;


public class initButtons {

    public void setButtons(Button b, int h, int w){
        b.setLayoutParams(new LinearLayout.LayoutParams(w, h));
    }
}

像这样调用方法

for (int i = 0; i < buttons.length; i++){
            setButtons(buttons[i], widthOfButtons, widthOfButtons);
        }

从 onCreate 替换下面的行

public void setButtons(buttons[i], widthOfButtons, widthOfButtons);

new initButtons().setButtons(buttons[i], widthOfButtons, widthOfButtons);

或通过

initButtons iButton = new initButtons();
iButton.setButtons(buttons[i], widthOfButtons, widthOfButtons);

不能在 For 循环内声明函数。 public void setButtons(buttons[i], widthOfButtons, widthOfButtons); 是一个声明。此外,您的功能中没有正文。尝试将行更改为 setButtons(buttons[i], widthOfButtons, widthOfButtons); 并在代码中添加一个函数:

public void setButtons(buttons[i], widthOfButtons, widthOfButtons) {
   doSomething...

}