Full Analysis of Android programming Learning Skills

Source: Internet
Author: User
Tags drawtext

Android programming learning is a very powerful SDK that combines XML-based layout with custom views. Now we have to wait for Google to release its first Android-based mobile phone, and use it.

This demo application demonstrates that the user's current longitude and latitude are displayed in the text box ). The onCreate constructor will be basically the same as the above example. In addition to adding keyboard processing, let's take a look at the onKeyDown code.

Next Let's explain this code. First, this code checks the currently pressed key, but has not started processing. Instead, the getLocation method is used to process all of this. Then, the flag is loaded and the getLocation method is called. The following is the code of the getLocation method.

 
 
  1. public class CustomView extends View 
  2. { LocateMe overlord; public CustomView(LocateMe pCtx) 
  3. { super(pCtx); overlord = pCtx; } public void onDraw(Canvas cvs) 
  4. { Paint p = new Paint(); String sLat = "Latitude: " + overlord.getLat(); 
  5. String sLon = "Longitude: " + overlord.getLon(); cvs.drawText(sLat , 32, 32, p);
  6.  cvs.drawText(sLon, 32, 44, p); } }public void CreateView()
  7.  { customView = new CustomView(this); } 

So far, the program began to become more interesting. However, unfortunately, there are still few Google Documents. After the variable Declaration of the program, we need to demonstrate some loading information. R. layout. loading conforms to another simple XML layout View.

By simply calling the setContentView method, you can use the Reprinted Information to repaint the screen. Readers should note that during compilation, Android programming will pack all XML layout data in advance. If we want to change the layout attribute after compilation, we have to do these things in the source program as required.

The only way to obtain the LocationManager is by calling the getSystemService () method. By using LocationManager, we can obtain a list of location providers. In a real handheld device, this list contains some GPS services. In fact, we want to choose a more powerful, more accurate GPS without additional services.

Now a GPS for testing is provided in the simulator, which comes from San Francisco. Custom GPS files can be uploaded and tested. If we want to test more complex applications, GPS from San Francisco may not be suitable. Currently, we can use location manager and location provider to call getCurrentLocation.

This method returns a snapshot of the current Location of the local machine. This snapshot will be provided as a Location object. In the handheld device, we can obtain the longitude and latitude of the current position. Now, using this virtual handheld device, we can get the final result of this example program: a custom view is displayed.

This custom Android programming Learning View obtains the longitude and violation test data and displays the data on the screen. This requires a pointer to LocateMe. The Activity class is the core of the entire application. The two methods are constructor and onDraw.

This constructor calls the constructor of the superclass and causes the interruption of the Activity pointer. The onDraw method creates a new Paint object. This object encapsulates color, transparency, and other theme information.) This object accesses the color topic. In this program, the strings for display are installed, and the canvas pointer is used to draw them to the screen. This looks very similar to the canvas of the j2_game we know.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.