If you want to directly go to your own Android interface, you can add a custom Action value to the receiver's IntentFilter. They all use the observer mode in the design mode, for your reference only.
One is to write Layout in a graphical way. The Layout is saved in an XML file and compiled into resources. It is loaded by the Activity in the program to setContentView ()), then, use the findViewById method to obtain the reference of each interface component.
Most people prefer the most intuitive method, that is, the dynamic generation method in code. Let's start with this. We will talk about visual programming and resource layout later.
1. Layout management Layout)
Each interface component is a child class of the View and can occupy a single screen. However, a really useful interface is a combination of these components. In the Android interface, various Layout components are used for Layout management, this is basically the same as some AWT and SWING interfaces in the traditional J2SE.
2. A separate interface element:
- Public class HelloActivity extends Activity {
- /** Called when the activity is first created .*/
- @ Override
- Public void onCreate (Bundle savedInstanceState ){
- Super. onCreate (savedInstanceState );
- TextView TV = new TextView (this );
- TV. setText ("Hello, World! ");
- This. setContentView (TV );
- }
- }
- Layout is not used here, which is a separate component method. You can also change it:
- Super. onCreate (savedInstanceState );
- Button btn = new Button (this );
- Btn. setText ("TestButton ");
- This. setContentView (btn );
- Compile and run a full screen Button. Of course, this is not the practical interface you want. We will use Layout to Layout it.
- Super. onCreate (savedInstanceState );
- Button btn = new Button (this );
- Btn. setText ("TestButton ");
- Button btn2 = new Button (this );
- Btn2.setText ("TestButton2 ");
- LinearLayout layout = new LinearLayout (this );
- Layout. setOrientation (LinearLayout. VERTICAL );
- Layout. addView (btn );
- Layout. addView (btn2 );
- This. setContentView (layout );
After compiling and running, you can see two buttons in the upper and lower order. Of course, for the layout manager, AWT is used on PC and SWING is no stranger. I will not go into details here. How can we respond to the event? It's easy to guess.
In AWT, the Listener is used to process event responses in the cell phone's j2s, And the Android interface is not refined. This is the same as the Observer in Blackberry and Symbian. Both use the observer mode of the design mode. The following is an example of Event Response.
- Simple and easy-to-understand Android code explanation
- Describe how to use Android Intent
- Describes the relationship between Android and other systems
- Learn how to operate on Android phones in a few minutes
- Can Google's Android mobile phone stand firm in China?
Steps:
1. generate two buttons and configure the Click Event listener as HelloActivity. This class implements the OnClickListener interface.
2. Put the Button into the layout and display two buttons according to the layout
3. Press a Button to generate a Click event and call the OnClick interface function of HelloActivity.
4. Determine which View (Button) is the value of the View parameter ). Rewrite the tititile content of the Activity. Note: Do not compare the View. getId (). By default, the Id value of each component is-1 unless the Id value is set manually. when visualized programming is used, an Id value is automatically generated for the component.