我想在Java類中的Android中創建佈局。我需要用戶1之間引入一個號碼20,這創造用戶具有chosen.I要創建動態按鈕butttons的號碼,我有這樣的代碼:動態按鈕Android佈局
package com.example.nuevo;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
public class ControladorResuelto extends Activity {
protected Controlador controlador;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
LinearLayout buttonsLayout = (LinearLayout)findViewById(R.id.linearlayoutUp);
int nMallas = controlador.getnMallas();
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
for(int i=0;i<nMallas;i++){
Button button = new Button(this);
button.setText("Buttin "+(i+1));
buttonsLayout.addView(button, layoutParams);******
}
setContentView(R.layout.panel_resuelto);
}
我有一個錯誤的與星號
什麼是具體的錯誤信息? NPE? –
是纏着贓物,這是,但現在我有另一個問題,我動態創建的3個按鈕是垂直佈局,現在我已經將線性佈局更改爲水平,他們不會出現你正在發生什麼? – user3232094