开发者

RemoteViews id in loops?

I've pretty much given up on dynamic remoteviews, but I still have about 20 remoteViews with 3-4 method calls on each in my onUpdate method. Now the problem is, can I have an iterator on RemoteViews subView id for a loop?

EDIT Ok, here's the code, I tried using bookmarkcounter as a iterator since the R class generates R.id.widget* * as a incrementing number (by one). But it doesn't work.

    @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {

    Cursor cursor;
 开发者_StackOverflow   String SORT_BY_COLUMN = Constants.SORT_BY_COLUMN;
    String SORT_ORDER = Constants.SORT_ORDER;
    int bookmarkIdCounter = R.id.widget_bookmark_1;
    Bitmap bitmap;

    HashMap<Integer, String> urls = new HashMap<Integer, String>();

    ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);

    RemoteViews updateViews = new RemoteViews(
            context.getPackageName(), R.layout.widget_main);
    RemoteViews bookmarks = new RemoteViews(
            context.getPackageName(), R.layout.widget_bookmarks);;

        cursor = context.getContentResolver().query(
                Browser.BOOKMARKS_URI, Constants.projection, Constants.selection, 
                null, SORT_BY_COLUMN + " " + SORT_ORDER);

        if(cursor.moveToFirst()) {
            ByteArrayInputStream blobImage;

            do{

               blobImage = new ByteArrayInputStream(
                       cursor.getBlob(cursor.getColumnIndex(BookmarkColumns.FAVICON)));

               bitmap = BitmapFactory.decodeStream(blobImage);
               bitmap = Bitmap.createScaledBitmap(
                       bitmap, Constants.FAVICON_SIZE, Constants.FAVICON_SIZE, false);
               bookmarks.setImageViewBitmap(bookmarkIdCounter, bitmap);

               bookmarks.setInt(bookmarkIdCounter, "setBackgroundColor", Color.WHITE);

               urls.put(bookmarkIdCounter,
                       cursor.getString(
                                cursor.getColumnIndex(BookmarkColumns.URL)));
               bookmarkIdCounter++;
            } while (cursor.moveToNext() && (bookmarkIdCounter < 2));
         }
        updateViews.addView(R.id.widget_main_container, bookmarks);
        cursor.deactivate();
        appWidgetManager.updateAppWidget(thisWidget, updateViews);
}


RemoteViews is not a View nor does it contain Views.

It is a way to "describe" a View and have it created in some other process. Basically it's just a set of actions that must be performed to build a View.

As there are no Views inside it there is no way to retrieve/iterate a list of subViews.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜