Android Widget (2) use configure and androidwidget

Source: Internet
Author: User

Android Widget (2) use configure and androidwidget

You need to perform some operations before adding Widgets. You can use the configuration activity.

Add the configuration activity (configure = activity) on the basis of the previous implementation ). When a Widget is added, an Activity is opened for configuration,

<appwidget-provider....android:configure="com.stone.ui.AppWidgetConfigureActivity" ></appwidget-provider>


Configuration activity implementation:

Package com. stone. ui; import android. app. activity; import android. appwidget. appWidgetHost; import android. appwidget. appWidgetManager; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import com. stone. r;/** configuration part * Add setResult (RESULT_CANCLE) before setContentView () function in onCreate. If the BACK button is pressed before Activity Initialization is complete, the Wid Get will not start; * after the setContentView () function (not necessarily in onCreate, before the Activity exits ), add the following settings to specify the widgets to be started */public class AppWidgetConfigureActivity extends Activity implements OnClickListener {Button config1, config2, config3; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); Intent intent = getIntent (); Bundle extras = intent. getExtras (); if (extras! = Null) {int widgetid = extras. getInt (AppWidgetManager. EXTRA_APPWIDGET_ID,-1); // obtain the widgetid from the intent. // the notification that the appwdiget configuration has canceled Intent reslut = new Intent (); reslut. putExtra (AppWidgetManager. EXTRA_APPWIDGET_ID, widgetid); setResult (RESULT_CANCELED, reslut); System. out. println ("result cancel");} setContentView (R. layout. switch_configure); config1 = (Button) findViewById (R. id. btn_config1); config2 = (Button) findVi EwById (R. id. btn_config2); config3 = (Button) findViewById (R. id. btn_config3); config1.setOnClickListener (this); config2.setOnClickListener (this); config3.setOnClickListener (this);} @ Overrideprotected void onResume () {super. onResume ();} private void onCompletedConfigure () {Intent intent = getIntent (); Bundle extras = intent. getExtras (); if (extras! = Null) {int widgetid = extras. getInt (AppWidgetManager. EXTRA_APPWIDGET_ID,-1); // obtain the widgetid from the intent // notify that the appwdiget configuration has been completed Intent reslut = new Intent (); reslut. putExtra (AppWidgetManager. EXTRA_APPWIDGET_ID, widgetid); setResult (RESULT_ OK, reslut); System. out. println ("result OK"); finish (); System. out. println ("finish OK") ;}@ Overridepublic void onClick (View v) {if (v = config1) {// do config1} else if (v = config2) {// do config2} else if (v = config3) {// do config3} onCompletedConfigure ();}}

Switch_configure.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <Button     android:id="@+id/btn_config1"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="config1"/><Button     android:id="@+id/btn_config2"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="config2"/><Button     android:id="@+id/btn_config3"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="config3"/></LinearLayout>



Do you have any suggestions for registering a security officer during an interview with Foxconn?

INTERVIEW TIPS
Aquarius is both an alternative and good at being funny. When applying for and choosing a job, it will unconsciously work in the creative industry. Its novel and distinctive clothes may make these companies look strange and conform to the expectations of the other party. However, when talking about Aquarius, it is easy to fall into extreme ideas and comments, but it will scare the other party. It is recommended that Aquarius wear a balanced and perfect white crystal. Besides, white crystal, also known as Guan yunshi, can help your work!

I have helped you uninstall the program due to a widget development problem on android. The desktop shows that an error occurred while loading the widget ......

The launcher issue occurs when the application is uninstalled and not deleted. The desktop is not deleted because your shortcut exists in the launcher database.

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.