[Lazarus] Android Target GUI

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Fri Feb 17 10:23:46 CET 2012


On Fri, Feb 17, 2012 at 9:11 AM,  <michael.vancanneyt at wisa.be> wrote:
> Android uses XML files to specify the layout. This is the recommended way by
> Google. You can build the GUI in code as well, but then you're pretty much
> in uncharted territory.

It is pretty trivial to build the UI without XML. I never used the XML
part while programming for Android. For example (in pseudo-code):

procedure TMyActivity.OnCreate;
var
  layout: TAbsoluteLayout;
  params: TAbsoluteLayout_LayoutParams;
  tv: TTextView;
  et: TTextView;
  btn: TButton;
  ClickCount: Integer = 0;
begin
  // Prepares the UI of the program
  layout := TAbsoluteLayout.Create;

  tv := TTextView.Create;
  tv.setText('The first Pascal Android application =)');
  params := TAbsoluteLayout_LayoutParams.Create(320, 300, 0, 120);
  layout.addView(tv, params);
  params.Free;

  et := TEditText.Create;
  et.setText('edit me please');
  params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 0);
  layout.addView(et, params);
  params.Free;

  btn := TButton.Create;
  btn.setText('Go!');
  btn.setOnClickListener(@buttonClickCallback);
  params := TAbsoluteLayout_LayoutParams.Create(320, 50, 0, 60);
  layout.addView(btn, params);
  params.Free;

  Activity.setContentView(layout);
end;

-- 
Felipe Monteiro de Carvalho




More information about the Lazarus mailing list