3

Como puedo crear varios botones en tiempo de ejecución en linearLayout en xamarin c# hasta el momento este es mi código

Button btn = new Button(this);

btn.LayoutParameters = lparams; 
btn.Text = ("Video"+ 1);
btn.Id= (1);
this.LinearBotones.AddView(btn);

pero tengo un error de

System.NullReferenceException: Object reference not set to an instance of an object.

4
  • 1
    En que linea te da ese error? Podrias poner más detalles de la excepción? this.LinearBotones está inicializado? el 4 ago. 2017 a las 10:17
  • 1
    en la ultima linea es el error. containerBotones = FindViewById<LinearLayout>(Resource.Id.containerBotones); for (int i = 1; i <= 30; i++) { Button btn = new Button(this); btn.Text = "Video " + i; btn.SetBackgroundColor(Android.Graphics.Color.Red); this.containerBotones.AddView(btn, ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); }
    – Rony Reyna
    el 4 ago. 2017 a las 11:17
  • 2
    Que esta usando? xamarin forms o xamarin android?
    – Lcop
    el 4 ago. 2017 a las 20:16
  • Por curiosidad hermano, ¿Lograste solucionarlo?
    – fredyfx
    el 26 mar. 2018 a las 22:53

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.