我想显示存储在Firebase中的图像。我可以显示本地图像,但不确定如何从Firebase下载图像。
这是我的适配器类
public class ownPagerAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;
private Context context;
private int[] image = {R.drawable.pix2,R.drawable.pix1,R.drawable.pix4};
public ownPagerAdapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
return image.length;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return view==o;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
layoutInflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate(R.layout.lay,null);
ImageView imageView=(ImageView)view.findViewById(R.id.imageV);
Glide.with(context).load(image[position]).into(imageView);
ViewPager vp=(ViewPager)container;
vp.addView(view,0);
return view;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
ViewPager vp=(ViewPager)container;
View view=(View)object;
vp.removeView(view);
}
}
下面是我要显示图像的仪表板类
public class DashboardFragment extends Fragment {
View v;
ViewPager viewPager;
TabLayout tabLayout;
public DashboardFragment() {
// Required empty public constructor
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_dashboard, container, false);
viewPager = v.findViewById(R.id.viewPa);
viewPager.setPadding(10, 0, 10, 0);
ownPagerAdapter own = new ownPagerAdapter(getActivity());
viewPager.setAdapter(own);
tabLayout = v.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager, true);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new MyTimer(), 5000, 6000);
return v;
}
class MyTimer extends TimerTask {
@Override
public void run() {
if (getActivity() != null)
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (viewPager.getCurrentItem() == 0) {
viewPager.setCurrentItem(1);
} else if (viewPager.getCurrentItem() == 1) {
viewPager.setCurrentItem(2);
} else if (viewPager.getCurrentItem() == 2) {
viewPager.setCurrentItem(0);
}
}
});
}
}
}
您能指导我如何从火力发电厂中挖掘图像,而不是从可绘制对象中加载图像吗?