2011-02-12 73 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