Also check out Boxing Clock for Android (and MABG), search Stack Overflow, read Android Developers Guide and Reference.
Toast
private void tToast(String s) {
Context context = getApplicationContext();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, s, duration);
toast.show();
}
Lifecycle
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
The rest have a shorter syntax: onResume(), onStop()…
public void onResume() {
super.onResume();
tToast("onResume");
}
Button
public void goButtonClicked(View v) { }
<Button android:text="Go!" android:onClick="goButtonClicked"
android:id="@+id/goButton"></Button>
TextView
final TextView q = (TextView) findViewById(R.id.q); String s = q.getText().toString();
out.setText("Foo bar");
out.setText(String.valueOf(x*x));
Canvas
public class HelloCanvasActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TCanvas tCanvas = new TCanvas(this);
setContentView(tCanvas);
}
public class TCanvas extends View {
public TCanvas(Context context) {
super(context);
}
public void onDraw(Canvas canvas) {
canvas.drawColor(Color.GREEN);
}
} }
Install
$ sudo apt-get -y intall eclipse
Eclipse: Help: Install New Software: https://dl-ssl.google.com/android/eclipse/ (IIRC, try without SSL if doesn’t work).
Follow instructions, accept licenses, restart eclipse when asked.
New Android Project
Eclipse: File: New: Project…: Android: Android Project
Project name: BoxingClock (One word, small or camelcase, will be folder name)
Build target: 2.2 API 8 (what you installed & what’s popular in the market)
Application name: BoxingClock the Nyrkkeilykello (Anything, shows in Android title bar)
Package name: com.botbook.foo (domain reversed, use example.com if you don’t have one)
Create Activity: BoxingClock (Class name, start Capitalized, camelcase)
Min SDK version: 8 (same as build target)
Edit: Fixed typo in code. Drawing on Canvas
