A concise tutorial on how to create and use Android programming widgets

This article describes the creation and use of Android programming widget. Share with you for your reference, as follows:

There are detailed methods on how to create a widget in Android reference. Here is a brief description. For details, you can check the reference provided in the Android SDK.

To create a widget, it is divided into the following steps:

(1) Create a class and let it inherit the class appwidgetprovider. There are many methods in the appwidgetprovider, such as ondelete (context, int []), onenable (context), etc., but generally we just override the onupdate (context, appwidgetmanager, int []) method. In this method, we start the class of background service, generally thread class or service class in Android. In this class, we obtain data from the server, process it and display it in the widget.

(2) On your Android menifest Add a receiver tag in XML to point to your AppWidget provider subclass. The contents are as follows:

Explain the above code:

The first line specifies that the recipient of the widget is jiwaiwidget, that is, the subclass of appwidgetprovider you created;

The second line specifies the tag name of the widget, and the value is string under the value directory App in XML_ Name value;

The third line specifies the icon of the widget, and the value is jiwai picture in drawable directory;

The fourth line - the sixth line is provided in the Android document;

The seventh line specifies the descriptor information of the widget. The description defines the relevant information of the widget, such as the width, length and automatic update interval of the widget. The description is located in info.xml directory XML.

(3) Write the provider file information of your widget (in this case, XML / info. XML)

Android: updateperiodmillis is the time interval of automatic update, and Android: initiallayout is the interface description file of the widget. Android: configure is optional. If your widget needs to start an activity first, you need to set this item as your activity. In this case, you need your muttering account and password, so you should first display an activity, enter your account and password, and then display the obtained information in your widget.

(4) Write the AppWidget in the layout directory XML file to configure the interface information of your widget:

The widget includes three textviews, two for displaying squiggly information and one for displaying user name. The above code is relatively simple, so it will not be explained.

(5) Because you need an activity object to input account information, create a new login. Login in the layout directory XML as the configuration file of activity:

There are two edittexts for entering user names and passwords, and a button object. The preparation work is almost done. Now you can write the code.

Here is another case for your reference: http://www.jb51.net/books/40184.html

More readers interested in Android related content can view the special topics of this site: summary of Android basic components usage, introduction and advanced tutorial of Android development, summary of Android resource operation skills, summary of Android view skills and summary of Android control usage

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>