2013-01-31 61 views
0

我的小工具在加載小工具時出現問題,無法使用。小工具:沒有任何例外,小工具無法打開

這是我在logcat輸出中收到的輸出,但我不確定它的含義。

W/de.vogella.android.widget.example(1613): onUpdate method called 
W/AppWidgetHostView(412): updateAppWidget couldn't find any view, using error view 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:394) 
W/AppWidgetHostView(412): at com.android.launcher2.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:54) 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:376) 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:101) 
W/de.vogella.android.widget.example(1664): onUpdate method called 
W/de.vogella.android.widget.example(1664): onUpdate method called 
W/de.vogella.android.widget.example(1664): onUpdate method called 
W/de.vogella.android.widget.example(1705): onUpdate method called 
W/de.vogella.android.widget.example(1744): onUpdate method called 
W/AppWidgetHostView(412): updateAppWidget couldn't find any view, using error view 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:394) 
W/AppWidgetHostView(412): at com.android.launcher2.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:54) 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:376) 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:101) 
W/de.vogella.android.widget.example(1744): onUpdate method called 
W/AppWidgetHostView(412): updateAppWidget couldn't find any view, using error view 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:394) 
W/AppWidgetHostView(412): at com.android.launcher2.LauncherAppWidgetHostView.updateAppWidget(LauncherAppWidgetHostView.java:54) 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:376) 
W/AppWidgetHostView(412): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:101) 

OnUpdate()方法是使用服務觸發。我已經發布了以下服務內容:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, 
     int[] appWidgetIds) { 

    Log.w(LOG, "onUpdate method called"); 
    // Get all ids 
    ComponentName thisWidget = new ComponentName(context, 
     MyWidgetProvider.class); 
    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget); 

    // Build the intent to call the service 
    Intent intent = new Intent(context.getApplicationContext(), 
     UpdateWidgetService.class); 
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, allWidgetIds); 

    // Update the widgets via the service 
    context.startService(intent); 
    } 

我覺得問題出在佈局上。如果我想將其更改爲字幕文本,那麼我會遇到這個問題。佈局是:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_margin="8dip" 
    android:background="@drawable/myshape" > 

    <TextView 
     android:id="@+id/update" 
     android:layout_width="200dp" 
     android:duplicateParentState="true" 
     android:ellipsize="marquee" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:marqueeRepeatLimit="marquee_forever" 
     android:scrollHorizontally="true" 
     android:singleLine="true" 
     android:text="Loading... More text to see if it spans or not and want more" > 

     <requestFocus 
      android:duplicateParentState="true" 
      android:focusable="true" 
      android:focusableInTouchMode="true" /> 
    </TextView> 

</LinearLayout> 

錯誤消息是什麼意思,爲什麼不是我的部件加載?

+1

任何源代碼? onUpdate方法可能是一個線索。 – Murat

+0

分享你的佈局xml。 – StarsSky

+0

@StarsSky請立即檢查。正如我所說的,問題出在我修改了textview以使其成爲可選字幕之後。 –

回答

0

我認爲這可能對其他人有用。

通常,爲了讓選框運行,在一項活動中,我們設置了TextView.setSelected(true)。在小部件中,應該使用標籤requestfocus在xml文件內完成。以防萬一,我已經發布了工作XML文件。

<TextView 
    android:id="@+id/update" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:ellipsize="marquee" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:freezesText="true" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:paddingLeft="15dip" 
    android:paddingRight="15dip" 
    android:scrollHorizontally="true" 
    android:singleLine="true" > 

    <requestFocus 
     android:duplicateParentState="true" 
     android:focusable="true" 
     android:focusableInTouchMode="true" /> 
</TextView> 

乾杯。