Hallo,
Ich habe ein Problem bei der Programmierung des folgenden Widgets:
StundenplanWidget.java << der AppWidgetProvider
Code
public class StundenplanWidget extends AppWidgetProvider {
private String actualDay;
private final String[] weekdays = new String[]{DaysOfWeek.SUNDAY, DaysOfWeek.MONDAY, DaysOfWeek.THUESDAY, DaysOfWeek.WEDNESDAY, DaysOfWeek.THURSDAY, DaysOfWeek.FRIDAY, DaysOfWeek.SATURDAY};
private RemoteViews view;
private Database db;
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
db = new Database(context);
this.actualDay = weekdays[new Date().getDay()];
for(int widgetId : appWidgetIds)
{
this.view = new RemoteViews(context.getPackageName(), R.layout.widget_timetable);
Intent touchIntent = new Intent(context, TouchActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, touchIntent, 0);
view.setOnClickPendingIntent(R.id.daybefore, pendingIntent);
view.setOnClickPendingIntent(R.id.daynext, pendingIntent);
appWidgetManager.updateAppWidget(widgetId, view);
}
db.close();
}
}
Alles anzeigen
TouchActivity.java << Die Activity die gestartet werden sollte
Code
public class TouchActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.daynext).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView txtView = (TextView) v.findViewById(R.id.day);
txtView.setText("Stundenplan");
}
});
super.onCreate(savedInstanceState);
}
}
Alles anzeigen
widget.xml
Code
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="142dip"
android:minHeight="214dip"
android:updatePeriodMillis="180000"
android:initialLayout="@layout/widget_timetable"
/>
Die Manifest Datei
Code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.tripwire.timetable"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Stundenplan"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".widget.StundenplanWidget" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" />
</receiver>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
Alles anzeigen
Das Problem ist beim Klicken der Buttons R.id.daybefore oder R.id.daynext schreibt die LogCat:
02-05 07:53:47.008: INFO/ActivityManager(578): Starting activity: Intent { comp={at.tripwire.timetable/at.tripwire.timetable.widget.TouchActivity} }
Aber es tut sich nichts
lg