I'm trying to learn how to make Widgets and I want to make one with a listView.
In the normal Activity of the app I do the typical of:
ListView lv = (ListView) findViewById(R.id.lv);
AdapterLV adapter = new AdapterLV(getContext(),R.layout.fila, arrayList);
lv.setAdapter(adapter);
But when I try it in the widget code it does not let me do it
public class MiWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context,
AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
//Aquí intento el findViewById y todo lo demás...
}
}
<FrameLayout
android:id="@+id/frmWidget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="5dp">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
Manifest:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MiWidget" android:label="Mi Primer Widget">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/miwidget_wprovider" />
</receiver>
</application>
How do I have to do it?