2011-07-05 48 views
0

我有一個小部件,有一個按鈕和一個圖像按鈕。 我希望如果你點擊圖像按鈕,用edittext打開一個透明活動。 例如我們填寫01 比單擊正常按鈕時,它將加載顯示html文件01.html的webview。 這可能嗎?如何使用主屏幕小部件上的按鈕?

的代碼,我是:

package com.kerk.liedboek.widget; 

import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 
import android.widget.RemoteViews; 
import android.widget.Toast; 

    public class main extends AppWidgetProvider { 

     public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget"; 
     public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget"; 

     @Override 
     public void onUpdate(Context context, AppWidgetManager 
appWidgetManager, 
     int[] appWidgetIds) { 
      Intent i = new Intent(context, edit.class); 
      PendingIntent pi = PendingIntent.getBroadcast(context,0, i,0); 
      RemoteViews rv = new RemoteViews(context.getPackageName(), 
R.layout.main); 
      rv.setOnClickPendingIntent(R.id.button_one, pi); 

      Intent i2 = new Intent(context, webview.class); 
      PendingIntent pi2 = PendingIntent.getBroadcast(context,0, i2,0); 
      RemoteViews rv2 = new RemoteViews(context.getPackageName(), 
R.layout.main); 
      rv2.setOnClickPendingIntent(R.id.button_two, pi2); 

    } 
} 

我是新來的機器人,而我現在我是一個福利局。但我希望你瞭解我,你可以幫助我。 Gaauwe

編輯:

我logcat的是:

07-09 14:19:31.070:ERROR/AndroidRuntime(381):致命異常:主 07-09 14:19:31.070: ERROR/AndroidRuntime(381):java.lang.RuntimeException:無法實例化接收器com.liedboek.widget.aantekening:java.lang.ClassCastException:com.liedboek.widget.aantekening 07-09 14:19:31.070:ERROR/AndroidRuntime(381):在android.app.ActivityThread.handleReceiver(ActivityThread.java:1773) 07-09 14:19:31.070:錯誤/ AndroidRuntime(381):在android.app.ActivityThread.access $ 2400 ActivityThread.java:117) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:981) 07-09 14:19:31.070: ERROR/AndroidRuntime(381):at android.os.Handler.dispatchMessage(Handler.java:99) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):at android.os.Looper.loop(Looper。 java:123) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):at android.app.ActivityThread.main(ActivityThread.java:3683) 07-09 14:19:31.070:ERROR/AndroidRuntime( 381):java.lang.reflect.Method.invokeNative(Native Method) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):at java.lang.reflect.Method.invoke(Method.java:507 ) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java :839) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):在dalvik.system.NativeStart.main(本地方法) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):引起:java.lang.ClassCastException:com.liedboek.widget。 (381):at android.app.ActivityThread.handleReceiver(ActivityThread.java:1764) 07-09 14:19:31.070:ERROR/AndroidRuntime(381):錯誤/ AndroidRuntime(381) ... 10更多 07-09 14:19:31.101:WARN/ActivityManager(69):進程com.liedboek.widget崩潰了太多次:kill!

但我的代碼是另一碼,同時也是一個按鈕控件:

包com.liedboek.widget;

import android.app.Activity; 
import android.app.PendingIntent; 
import android.appwidget.AppWidgetManager; 
import android.appwidget.AppWidgetProvider; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.RemoteViews; 

public class main extends AppWidgetProvider { 

public static String ACTION_WIDGET_CONFIGURE = "ConfigureWidget"; 
public static String ACTION_WIDGET_RECEIVER = "ActionReceiverWidget"; 

@Override 
public void onUpdate(Context context, AppWidgetManager 
appWidgetManager, 
    int[] appWidgetIds) { 
    // Create an Intent to launch ExampleActivity 
    Intent intent = new Intent(context, aantekening.class); 
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 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.main); 
    views.setOnClickPendingIntent(R.id.button_one, pendingIntent); 

    // Tell the AppWidgetManager to perform an update on the current app widget 
    appWidgetManager.updateAppWidget(appWidgetIds, views); 



    } 
} 

回答

1

而不是使用getBroadcast,你可能想使用getActivity

+0

我不明白你。你能在網上給我一個例子,或者你能給我一個代碼嗎? – Gaauwe

+1

請閱讀你粘貼的代碼(我猜你沒有寫它或什麼)...然後你會明白;) – Cristian

+0

我把它放在我的代碼中,但是當我點擊一個按鈕時, 。我不明白嗎? – Gaauwe