我想创建一个小部件,当点击打开一个对话框,一个autocompletetextview(来自main.class)和mainclass执行功能..这是我的小部件类,请告诉我应该穿什么在Android清单也。 THX小部件自动完成的TextView
public class AppWidget extends AppWidgetProvider
{
@Override
public void onReceive(Context ctxt, Intent intent)
{
if(intent.getAction()==null)
{
ctxt.startService(new Intent(ctxt,ToggleService.class));
}
else
{
super.onReceive(ctxt, intent);
}
}
@Override
public void onUpdate(Context context,AppWidgetManager appWidgetManager, int [] appWidgetIds)
{
context.startService(new Intent(context,ToggleService.class));
//RemoteViews buildUpdate(context);
}
public static class ToggleService extends IntentService
{
public ToggleService() {
super("AppWidget$ToggleService");
}
@Override
protected void onHandleIntent(Intent intent)
{
ComponentName me = new ComponentName(this,AppWidget.class);
AppWidgetManager mgr= AppWidgetManager.getInstance(this);
mgr.updateAppWidget(me,buildUpdate(this));
}
private RemoteViews buildUpdate(Context context)
{
RemoteViews updateViews=new RemoteViews(context.getPackageName(),R.layout.widget);
Intent i=new Intent(this, AppWidget.class);
PendingIntent pi= PendingIntent.getBroadcast(context,0, i,0);
updateViews.setOnClickPendingIntent(R.id.phoneState,pi);
return updateViews;
}
} }在res
widgetxml //
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/phoneState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher"
/>
</RelativeLayout>
//和widget_provider.xml/XML
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="79px"
android:minHeight="79px"
android:updatePeriodMillis="1800000"
android:initialLayout="@layout/widget">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Loading..." />
//和部分从我的清单
<receiver android:name=".AppWidget"
android:label="Caller"
android:icon="@drawable/ic_launcher" >
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_provider"
/>
</receiver>
<service android:name=".AppWidget$ToggleService" />
你的标题是这么久......像“不使用关键字的任何人都可以referm我一些示例我应该怎么做“ – 2012-03-11 18:28:19
嗨托尼,这是imran。你想开始一个服务或活动? – 2012-03-11 18:51:40
当我按下我想用我的autocompletetextview(其搜索联系人和当点击调用它们),反正这是可能的,当点击小工具来显示自动完成(因为autocomplete..cant是一个小部件),并帮助我的小工具正如我告诉你对话框不小部件点击强制执行开放执行该自动完成在Main.class执行命令...... THX – Tony 2012-03-11 18:59:36