Difference between revisions of "Android Programming"
From Lazarus wiki
Jump to navigationJump to searchSekelsenmat (talk | contribs) |
Sekelsenmat (talk | contribs) |
||
Line 68: | Line 68: | ||
end. | end. | ||
</delphi> | </delphi> | ||
+ | |||
+ | [[Image:Simple Android app.png]] | ||
==References== | ==References== | ||
* http://developer.android.com/guide/developing/other-ide.html | * http://developer.android.com/guide/developing/other-ide.html |
Revision as of 19:20, 16 December 2010
Go back to Android Interface
Knowing general Android programming can be very useful to help developing the Lazarus Android Interface.
Creating a new Java Android Application
See here: http://developer.android.com/guide/developing/other-ide.html
Using the Android API from Pascal
Here is an example Pascal application written for Android.
<delphi> program pascalnotes4android;
{$mode objfpc}{$H+}
uses
Classes, androidpipescomm, androidui, javalang;
{$R *.res}
var
layout: TAbsoluteLayout; params: TAbsoluteLayout_LayoutParams; tv: TTextView; et: TTextView; btn: TButton;
begin
// Here add any initialization. // Any initialization code will be run inside Activity.onCreate, // so keep it as short as possible! // It should mostly contain GUI initialization // User interface
// 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);
// Now tell Java that the initialization has finished myAndroidPipesComm := TAndroidPipesComm.Create; myAndroidPipesComm.InitializationFinished(); // Here you can add any other initialization, // specially non-GUI code
// Now we block our execution waiting for callbacks from Java myAndroidPipesComm.MessageLoop();
end. </delphi>