I have created a custom view and drawing a bitmap image. How can i use this view in my widget..Below is the code
public class MyWidget extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for(int i=0 ; i<appWidgetIds.length; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
views.setImageViewBitmap( ... );
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
public class myCustomView extends View {
Bitmap img;
public myCustomView(Context context) {
super(context);
img = BitmapFactory.decodeResource(context.getResources(), R.drawable.myimg);
}
protected void onDraw(Canvas canvas) {
canvas.drawBitmap( img, 0, 0, new Paint() );
}
Unfortunately, you cannot use custom views in a homescreen widget.
For layouts you can use FrameLayout, LinearLayout and RelativeLayout. As views you can use AnalogClock, Button, Chromometer, ImageButton, ImageView, ProgressBar and TextView.
As of Android 3.0 more views are available: GridView, ListView, StackView, ViewFlipper and AdapterViewFlipper.
Source