2011-02-12 81 views
0

我一直在试图为我的窗口小部件添加配置屏幕,并且遇到了让它工作的问题。当我第一次将小部件添加到我的主屏幕时,配置屏幕显示正常,但当用户单击小部件时也会出现此配置屏幕。这是不工作的部分。Android窗口小部件点击不起作用

这里的代码的onUpdate:

Intent intent = new Intent(context, WidgetConfiguration.class);    
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);    
views.setOnClickPendingIntent(R.id.temperatureWidget, pendingIntent); 

这里有一个小部件布局(widget.xml)的XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/frame" 
android:clickable="true" 
android:focusable="true" 
android:id="@+id/temperatureWidget"> 
<ImageView 
    android:layout_marginTop="15px" 
    android:layout_marginLeft="25px" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/img_thermometer"/> 
<TextView 
    android:id="@+id/TextView01" 
    android:layout_marginTop="35px" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="12pt" 
    android:textColor="@color/black" 
    android:text=" Temp: "/> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="35px" 
    android:textSize="12pt" 
    android:textColor="@color/black" 
    android:id="@+id/txtTemperature"/> 

</LinearLayout> 

当我点击该窗口小部件,没有任何反应。有任何想法吗?

+0

RemoteViews意见=新的RemoteViews(context.getPackageName(),R.layout.widget); 我没有在您发布的XML中看到R.layout.widget。你确定你不是指两种不同的XML吗? – hanspeide 2011-02-12 23:21:24

+0

我发布的Xml是一个名为widget.xml的布局文件。 – 2011-02-13 04:13:35

回答

1

您需要添加一行在appwidget文档给出

appWidgetManager.updateAppWidget(appWidgetId, views); 
0

我有一种感觉,它是在你的xml布局的东西在小部件。你确定R.id.temperatureWidget是可点击的吗?这是一个按钮还是你的实际布局命名?

+0

是的,它是可点击的。它是小部件的LinearLayout。我也会添加外行代码。 – 2011-02-12 17:31:21