我有一個小部件,主要是做我想做的(開始一個意圖),但我想知道如何將多個意圖擠入一個小部件提供程序。有趣的小部件難題
我已經試過能完成這一操作所有常用的手段:
- 使用一個以上的意圖
- 用相同的主題設置 在這裏和那裏的幾個人說是最終第二控件故障。
通用代碼:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
Intent startIntent = new Intent(context, myClass.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, startIntent, 0);
// Get the layout for the App Widget and attach an on-click listener to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.MyWidget);
views.setOnClickPendingIntent(R.id.startBtn, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
所以我試圖找出如何獲得在widget更多然後一個按鈕。自從它成立三個,我知道其中一個作品,所以我在那裏的三分之一。
這裏是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" >
<TextView
android:id="@+id/startBtn"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_marginBottom="5dp"
android:background="@drawable/mybg"
android:gravity="center"
android:text="First Menu Item"
/>
<TextView
android:id="@+id/startBtn2"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_marginBottom="5dp"
android:background="@drawable/mybg"
android:gravity="center"
android:text="Second menu item" />
<TextView
android:id="@+id/startBtn3"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_marginBottom="5dp"
android:background="@drawable/mybg"
android:gravity="center"
android:text="Third menu item" />
</LinearLayout>
發佈的XML文件的內容R.layout.MyWidget – edthethird 2012-08-15 17:13:57
@edthethird星際很好的參考和XML已被添加。 – linuxrox 2012-08-15 17:22:29
哈哈它實際上是我的名字,沒有意識到這是一個比波普參考...雖然不錯的巧合! – edthethird 2012-08-15 17:31:02