Here, we do not use IDE and directly use the command line for processing.
1. Create a project
Here we use the commands in tools in andriod SDK:
Android Create project -- Target 2/
-- Path/workspace/andriod/learning/now -- activity now/
-- Package com. Wei. andriod. Learning. Now
2. Programming
In the src/COM/Wei/andriod/learning/now/directory on now. Java, This is the activity we need to process. In this example, we create a button to display the time when the button was last pressed or the time it was used to start ing.
Package com. Wei. andriod. Learning. now;
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. widget. Button;
Import java. util. date; // note that not all Java classes are valid in andriod. You can view andriod class reference.
// In andriod. in the view package, View. onClickListener is a public static interface which definition for a callback to be invoked when a view is clicked by an abstract void on Click (View v) method.
Public class Now extends Activity implements View. OnClickListener
{
Button button;
/** Called when the activity is first created.
* When activity start is enabled, onCreate is called first.
*/
@ Override
Public void onCreate (Bundle savedInstanceState)
{
/* First run the related initial processing of the parent class Activity onCreate */
Super. onCreate (savedInstanceState );
/* Create a button instance. When you click a button, call the onclick processing method of this instance. In this instance, we implement the view. onclicklistener interface. This is different from swing in Java. During jbutton click, actionevent events are often passed to actionlistener, and the processing method here is more to VC, through the onclicklistener instance, the onclick () method that triggers the onclick () method. */
Button = new button (this );
Button. setonclicklistener (this );
Updatetime ();
Setcontentview (button );
}
Public void onclick (view ){
Updatetime ();
}
Private void updatetime (){
Button. settext (new date (). tostring ());
}
}
3. Compile
Compile: ant1.8 is required, and the version is not enough. So apt-Get install ant1.8 is run.$ Ant debug
4. Load
Run the andriod command to open our simulator and install the following on the simulator:$ Ant installThen we can see our application now on the simulator and run it.
Related links:
My andriod development articles