首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Widget:无异常,widget未打开

Widget:无异常,widget未打开
EN

Stack Overflow用户
提问于 2013-02-01 05:34:06
回答 1查看 446关注 0票数 0

我的小部件在加载小部件时出现问题,并且无法正常工作。

这是我在logcat输出中收到的输出,但我不确定它是什么意思。

代码语言:javascript
运行
复制
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()方法。我已经发布了以下服务内容:

代码语言:javascript
运行
复制
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);
  }

我认为问题出在布局上。如果我想把它改为字幕文本,那么我就会遇到这个问题。布局是:

代码语言:javascript
运行
复制
<?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>

错误消息是什么意思?为什么没有加载我的小部件?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-01 05:58:23

我认为这可能对其他人有用。

通常,为了让字幕运行,在活动中,我们设置TextView.setSelected(true)。在小部件中,这应该在xml文件中使用标记requestfocus来完成。为了以防万一,我已经发布了工作的xml文件。

代码语言:javascript
运行
复制
<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>

干杯。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14635555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档