如何在viewpager中显示来自Firebase的图像

时间:2017-09-26 02:51:54

标签: android firebase android-fragments firebase-realtime-database firebase-storage

您好我是firebase框架的新手我尝试从firebase存储中检索图像但是我从教程Firebase Ui看到我不知道如何使用我的代码,我尝试了这个教程的viewpager代码{{ 3}}

在我的数据库中保持图像像这个数组imagename(“991ec0d99212d58b7980100929cf7a260ae6a84a,95f1f9a33bf5b8736785dd218ecb79e6c41c6b30,a0a73f247296021d659fe1ab1cb64c019bf566bd”)

并且此firebase存储保持图像

How to use viewpager show view with pageradapter

enter image description here

这是我的代码

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //add sample data
    ArrayList<Integer> picList = new ArrayList<Integer>();
    picList.add(R.drawable.pic01);
    picList.add(R.drawable.pic02);
    picList.add(R.drawable.pic03);

    MyPagerAdapter mAdapter = new MyPagerAdapter();

    //add View to Adapter
    for (int resource : picList) {
        ImageView iv = (ImageView) getLayoutInflater().inflate(R.layout.my_image,null);
        iv.setImageResource(resource);
        mAdapter.addView(iv);
    }

    ViewPager viewPager = (ViewPager)findViewById(R.id.pager);
    viewPager.setAdapter(mAdapter);

}

MypagerAdapter

  @Override
public int getItemPosition(Object object) {
    int index = views.indexOf(object);
    if (index == -1)
        return POSITION_NONE;
    else
        return index;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    View v = views.get(position);
    container.addView(v);
    return v;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView(views.get(position));
}

@Override
public int getCount() {
    return views.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
    return view == object;
}


public int addView(View v) {
    return addView(v, views.size());
}

public int addView(View v, int position) {
    views.add(position, v);
    notifyDataSetChanged();
    return position;
}

public int removeView(ViewPager pager, View v) {
    return removeView(pager, views.indexOf(v));
}

public int removeView(ViewPager pager, int position) {

    pager.setAdapter(null);
    views.remove(position);
    pager.setAdapter(this);

    return position;
}


public View getView(int position) {
    return views.get(position);
}

我希望每个人都可以帮我解决我的问题我试试1周不能这样做

谢谢

0 个答案:

没有答案