开发者

How to display images from url in StackView Widget with this

I have built a stackview widget for home Screen but i dont know how to load images into it so the user will be able to flip through the images and see different ones.

Here is the code i am using now and this is where the images are suppose to be downloaded and set to the remote View

I dont how to go about doing this and setting it to the remote view to display in the widget.

开发者_StackOverflow中文版

Here is the code i am using.. i followed the tutorial here on the developers website

http://developer.android.com/resources/samples/StackWidget/index.html

public class StackWidgetService extends RemoteViewsService {

@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {

    return new StackRemoteViewsFactory(this.getApplicationContext(), intent);


}
private static final int mCount = 10;
private List<WidgetItem> mWidgetItems = new ArrayList<WidgetItem>();
private Context mContext;
private int mAppWidgetId;
class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory{

    public StackRemoteViewsFactory(Context context, Intent intent){

        mContext = context;
        mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);

    }

    @Override
    public int getCount() {

        return mCount;
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public RemoteViews getLoadingView() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public RemoteViews getViewAt(int position) {

        RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
        rv.setTextViewText(R.id.widget_item, mWidgetItems.get(position).text);

        Bundle extras = new Bundle();
        extras.putInt(stackWidgetProvider.EXTRA_ITEM, position);
        Intent fillnIntent = new Intent();
        fillnIntent.putExtras(extras);
        rv.setOnClickFillInIntent(R.id.widget_item, fillnIntent);

        //Do heavy lifting here, Downloading images from a network or website.

        return rv ;
    }

    @Override
    public int getViewTypeCount() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public boolean hasStableIds() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onDataSetChanged() {
        // TODO Auto-generated method stub

    }

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub

    }


}

}


Have you tried including the images in the drawable or assets folder, and then loading the images from there? Once you know how to do that, then retrieving images from the web or other network location will be an easier jump.

As far as getting the image from the web, check out: http://asantoso.wordpress.com/2008/03/07/download-and-view-image-from-the-web/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜