No text that is hardcore in RemoteView in Widget RemoteView . The text in xml displayed without problems. Below is a listing.

  1. Manifesto:

     <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.alex.dzlesson06"> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <receiver android:name=".MyWidget"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/widget_metadata"/> </receiver> </application> </manifest> 
  2. Layout widget:

     <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/widget_latitude" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TEST" android:gravity="center" android:textSize="18sp"/> <TextView android:id="@+id/widget_longitude" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textSize="18sp"/> </LinearLayout> 
  3. Meta data:

     <?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:initialLayout="@layout/widget" android:minHeight="40dp" android:minWidth="110dp" android:updatePeriodMillis="0"> </appwidget-provider> 
  4. Widget code:

     public class MyWidget extends AppWidgetProvider { @Override public void onEnabled(Context context) { super.onEnabled(context); } @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); for (int id : appWidgetIds){ RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); remoteViews.setTextViewText(R.id.widget_latitude, "MY WIDGET"); appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); } } 

And another question after. Because this Widget without an app. How can you debug it?

    1 answer 1

    There is no way to debug in the traditional sense, because RemoteViews have no behavior, these are static data for display, I wrote about it recently: https://ru.stackoverflow.com/a/611785/193715

    Secondly, there is an oddity in the code. Note that updateAppWidget () is in two versions: the first parameter is the id of a certain view, and the first is the list id. If you use the list option, then why do you need an external for ?

    Thirdly, your code looks fine. The only hypothesis is that after reinstalling the application that creates the widget, it (the widget) will not update. Try to create a new instance of the widget, probably it will be all right.