SD カードからページ ビューアーへの画像の読み込みに問題があります。これは私が得たエラーです:
06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-0.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-0.jpg
06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-1.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-1.jpg
06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-2.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-2.jpg
06-21 09:12:03.795: D/skia(881): --- decoder->decode returned false
06-21 09:12:03.795: I/System.out(881): resolveUri failed on bad bitmap uri: file:///sdcard/DinEgen/852-3.jpg
06-21 09:12:03.795: V/Fotski(881): file:///sdcard/DinEgen/852-3.jpg
これは、新しいimageViewを追加するクラスです:
public class ServiceImages1 extends LinearLayout{
public ServiceImages1(Context context, String id) {
super(context);
init(id);
}
public ServiceImages1(Context context, AttributeSet attrs, String id) {
super(context, attrs);
init(id);
}
private void init(String id) {
File file;
file = new File("/sdcard/DinEgen/"+id);
ImageView imageView = new ImageView(getContext());
imageView.setImageURI(Uri.fromFile(file));
Log.v("Fotski", ""+Uri.fromFile(file));
addView(imageView);
}
}
これは私のpageViewerです:
final MyPagerAdapter adapter = new MyPagerAdapter(this);
viewPager.setAdapter(adapter);
if( adapter.getCount() > 18){
indicatorLayout.setVisibility(View.GONE);
}
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
public void onPageSelected(int page) {
indicatorLayout.removeAllViews();
for(int i = 0; i < adapter.getCount(); i++){
if(i==page){
indicatorLayout.addView(new IndicatorDotsView(getApplicationContext(), R.drawable.showpic_active));
}else{
indicatorLayout.addView(new IndicatorDotsView(getApplicationContext(), R.drawable.showpic_normal));
}
}
}
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
public void onPageScrollStateChanged(int arg0) {
}
});
}
public class MyPagerAdapter extends PagerAdapter {
private ArrayList<LinearLayout> views;
private ArrayList<LinearLayout> dots;
public MyPagerAdapter(Context context) {
views = new ArrayList<LinearLayout>();
dots = new ArrayList<LinearLayout>();
PhotoDao photoDb = new PhotoDaoImpl(context);
for(Photo photo: photoDb.findByParentType(parentType)){
views.add(new ServiceImages1(context, photo.getFileName()));
//photo.getFileName return picture name from sd card.
}
for(int i = 0; i< getCount(); i++){
if(i==0){
dots.add(new IndicatorDotsView(context, R.drawable.showpic_active));
}else{
dots.add(new IndicatorDotsView(context, R.drawable.showpic_normal));
}
}
for(int i = 0; i< getCount(); i++){
indicatorLayout.addView(dots.get(i));
}
}
@Override
public void destroyItem(View view, int arg1, Object object) {
((ViewPager) view).removeView((LinearLayout) object);
}
@Override
public void finishUpdate(View arg0) {
}
@Override
public int getCount() {
return views.size();
}
@Override
public Object instantiateItem(View view, int position) {
View myView = views.get(position);
((ViewPager) view).addView(myView);
return myView;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public void restoreState(Parcelable arg0, ClassLoader arg1) {
}
@Override
public Parcelable saveState() {
return null;
}
@Override
public void startUpdate(View arg0) {
}
}
このソリューションが機能しない理由がわかりません。私が必要としているのは、SDカードから写真を取得してビューページャーに入れることだけです。