Themelis
Themelis

Reputation: 4255

Android Widget displays error and updateAppWidget couldn't find any view

I’ve created a widget with the wizard. Then I’ve customized the layout. I tried to run but all I got is the error view of the widget “Problem loading widget”.

Checking the log I found this error:

W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view

It says that the system could not find any view, but my layout is defined in res/layout/ and declared in widget info xml file.

What am I missing? Here is the project on GitHub.

Upvotes: 1

Views: 863

Answers (1)

Elletlar
Elletlar

Reputation: 3234

You're not doing much that's wrong. The entire app widget is setup correctly. It is purely a layout issue. It doesn't seem to be happy with the complexity of the playback_widget.xml file. I changed the file to the following:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/playback_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/poster_imageview"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/ic_headset_mic_light_black_140dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title_textview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:textAlignment="center"
            android:textColor="@color/primaryTextColor"
            android:textSize="16sp" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="@dimen/default_text_padding">

            <ImageView
                android:id="@+id/player_previous"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginEnd="32dp"
                android:layout_marginRight="32dp"
                android:layout_toLeftOf="@+id/player_play_pause"
                android:src="@drawable/ic_skip_previous_white_32dp" />

            <ImageView
                android:id="@+id/player_play_pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/ic_play_arrow_white_40dp" />

            <ImageView
                android:id="@+id/player_next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="32dp"
                android:layout_marginStart="32dp"
                android:layout_toRightOf="@id/player_play_pause"
                android:src="@drawable/ic_skip_next_white_32dp" />


        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

The widget views appear fine now. I realise this probably isn't the exact layout that you're after, but you'll just have to play around with it until you find something that it is happy with.

Home screen widgets can be a bit tricky because you have a more limited set of views and less flexibility in terms of the layout.

Also I haven't checked but I'm not sure that the following view is allowed in homescreen widgets:

 <View
    android:layout_width="match_parent"
    android:layout_height="4dp"
    android:background="?colorAccent" />

Also if you have trouble getting that error to go away. Destroy the home screen widget and restart the phone. They sometimes get into a dorked up state during development.

But in any event your project is working fine for me after the playback_widget.xml change. Android 8.0.

Upvotes: 2

Related Questions