Say Hello World – Native Android app
Normally, I write Android apps using PhoneGap / Cordova, but I wanted to start looking into native apps, to tap into features such as SQLLite etc.
So, Here’s a first go at “Say Hello World”, an app with a button that pops up a toast saying “Hello World”.
I used eclipse to create a new blank Android app, then dropped a button onto the form. Set it’s ID to btnSayHello
Then in MainActivity.java I added the following code:
Button button = (Button)findViewById(R.id.btnHello);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), “Hello”, Toast.LENGTH_SHORT).show();
}
});
And, then following the prompts by eclipse, added some necessary imports
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
Bit of trial and error, but it’s starting to make sense…