我有主要活动:
public class Clip15 extends Activity{}
我想从主类Clip15中的类GenerateView调用tableLayout:
public class GenerateView {
public void generateInputView(String [] inputHeaderTvs, String [] inputTvs, Context context, LinearLayout inputLinearLayout){
final TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT, 1f);
final TableRow.LayoutParams rowParams = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
rowParams.bottomMargin = 0;
final TableLayout tableLayout = new TableLayout(context);
tableLayout.setLayoutParams(tableParams);
inputLinearLayout.addView(tableLayout);
TableRow rowOutputHeader = new TableRow(context);
rowOutputHeader.setLayoutParams(tableParams);
TextView outputHeader = new TextView(context);
outputHeader.setLayoutParams(rowParams);
outputHeader.setTextAppearance(context, R.style.outputHeaderTv);
outputHeader.setText("Dane wejściowe");
rowOutputHeader.addView(outputHeader);
tableLayout.addView(rowOutputHeader);
}}
有可能吗?
答案 0 :(得分:0)
将您的功能签名更改为:
public static void generateInputView(String [] inputHeaderTvs, String [] inputTvs, Context context, LinearLayout inputLinearLayout) {
//rest of the code
}
并使用正确的参数调用Clip类:
GenerateView.generateInputView(inputHeaders, inputTvs, context, inputLayout);
inputHeaders,inputTvs,context和inputLayout是您传递给上述函数的参数。它们应该已经初始化了。