ViewPager活动内容的变化时,幻灯片 [英] ViewPager Activity change content when slide
问题描述
我一直在四处寻找,但我想不通我怎么能修复了这个问题。
我使用的是@戴夫·莫里西的二次抽样放大图片浏览,是一个伟大的图书馆和它的作品完美,但我想要做一些改变。
对于每一个图像,用户将滑动欲显示具体描述。
所以这将是:
PIC1 | PIC2 | PIC3
DescriptionPic1 | DescriptionPic2 | DescriptionPic3
当我打开它,我可以看到的画面与下面的正确描述,但是当我滑块向左(或右),我可以看到后总是该项目的描述。
是因为方法的getItem()被调用两次,以使滑块更加流畅。
问题是,我想每个显示画面右下方的内容(介绍)。
我如何展示的内容完全当用户滑动图片?
任何帮助真的是AP preciate。
多谢你们
ViewPagerActivity.java
公共类ViewPagerActivity扩展FragmentActivity {私人ViewPager页面;
私人位图bmImg1;
私人位图bmImg2;
私人位图bmImg3;
私人字符串标记;
ArrayList的<&位图GT; IMAGES =新的ArrayList<&位图GT;();
的String [] descriptionPhoto;INT numpics = 1;
私人诠释position_pic;
私人字符串suggested_aperture;
私人字符串suggested_filter;
私人字符串suggested_iso;
私人字符串suggested_shutter;
私人字符串suggested_shot_level;
私人字符串suggested_lens;
私有String [] shot_levelPhoto;
私有String [] filterPhoto;
私有String [] aperturePhoto;
私有String [] shutterPhoto;
私有String [] isoPhoto;
私有String [] focal_lengthPhoto;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.view_pager);
FIS的FileInputStream;
的FileInputStream FIS2;
的FileInputStream fis3;
捆绑意图= getIntent()getExtras()。
descriptionPhoto = intent.getStringArray(descriptionPhoto); numpics =(int)的intent.get(numpics);
position_pic =(int)的intent.get(position_pic); suggested_aperture = intent.getString(suggested_aperture);
suggested_filter = intent.getString(suggested_filter);
suggested_iso = intent.getString(suggested_iso);
suggested_shutter = intent.getString(suggested_shutter);
suggested_shot_level = intent.getString(suggested_shot_level);
suggested_lens = intent.getString(suggested_lens); shot_levelPhoto = intent.getStringArray(shot_levelPhoto);
filterPhoto = intent.getStringArray(filterPhoto);
aperturePhoto = intent.getStringArray(aperturePhoto);
shutterPhoto = intent.getStringArray(shutterPhoto);
isoPhoto = intent.getStringArray(isoPhoto);
focal_lengthPhoto = intent.getStringArray(focal_lengthPhoto);
TextView的txtaperture_suggested =(的TextView)findViewById(R.id.aperture_suggested);
TextView的txtfilter_suggested =(的TextView)findViewById(R.id.filter_suggested);
TextView的txtiso_suggested =(的TextView)findViewById(R.id.iso_suggested);
TextView的txtlens_suggested =(的TextView)findViewById(R.id.lens_suggested);
TextView的txtshutter_suggested =(的TextView)findViewById(R.id.shutter_suggested);
TextView的txtshot_levelsuggested =(的TextView)findViewById(R.id.shot_levelsuggested); 如果(suggested_shot_level ==1){
txtshot_levelsuggested.setText(易);
/*txtshot_levelPhoto2.setText(\"Easy);
txtshot_levelPhoto3.setText(易); * / }否则如果(suggested_shot_level ==2){
txtshot_levelsuggested.setText(中);
/ * txtshot_levelPhoto2.setText(中);
txtshot_levelPhoto3.setText(中); * /
}否则如果(suggested_shot_level ==3){
txtshot_levelsuggested.setText(难);
/*txtshot_levelPhoto2.setText(\"Difficult);
txtshot_levelPhoto3.setText(难); * /
}其他{
txtshot_levelsuggested.setText(临);
/ * txtshot_levelPhoto2.setText(临);
txtshot_levelPhoto3.setText(临); * /
} txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens); TextView的txtshutterPhoto =(的TextView)findViewById(R.id.shutterPhoto);
TextView的txtshutterPhoto2 =(的TextView)findViewById(R.id.shutterPhoto2);
TextView的txtshutterPhoto3 =(的TextView)findViewById(R.id.shutterPhoto3); TextView的txtshot_levelPhoto =(的TextView)findViewById(R.id.shot_levelPhoto);
TextView的txtshot_levelPhoto2 =(的TextView)findViewById(R.id.shot_levelPhoto2);
TextView的txtshot_levelPhoto3 =(的TextView)findViewById(R.id.shot_levelPhoto3); TextView的txtaperturePhoto =(的TextView)findViewById(R.id.aperturePhoto);
TextView的txtaperturePhoto2 =(的TextView)findViewById(R.id.aperturePhoto2);
TextView的txtaperturePhoto3 =(的TextView)findViewById(R.id.aperturePhoto3); TextView的txtfilterPhoto =(的TextView)findViewById(R.id.filterPhoto);
TextView的txtfilterPhoto2 =(的TextView)findViewById(R.id.filterPhoto2);
TextView的txtfilterPhoto3 =(的TextView)findViewById(R.id.filterPhoto3); TextView的txtisoPhoto =(的TextView)findViewById(R.id.isoPhoto);
TextView的txtisoPhoto2 =(的TextView)findViewById(R.id.isoPhoto2);
TextView的txtisoPhoto3 =(的TextView)findViewById(R.id.isoPhoto3); TextView的txtlensPhoto =(的TextView)findViewById(R.id.lensPhoto);
TextView的txtlensPhoto2 =(的TextView)findViewById(R.id.lensPhoto2);
TextView的txtlensPhoto3 =(的TextView)findViewById(R.id.lensPhoto3); /*txtshutterPhoto.setText(shutterPhoto[0]);
如果(shutterPhoto.length→1){
txtshutterPhoto2.setText(shutterPhoto [1]);
如果(shutterPhoto.length→2){
txtshutterPhoto3.setText(shutterPhoto [2]); }
}
txtisoPhoto.setText(isoPhoto [0]);
如果(isoPhoto.length→1){
txtisoPhoto2.setText(isoPhoto [1]);
如果(isoPhoto.length→2){
txtisoPhoto3.setText(isoPhoto [2]);
}
}
txtfilterPhoto.setText(filterPhoto [0]);
如果(filterPhoto.length→1){
txtfilterPhoto2.setText(filterPhoto [1]);
如果((filterPhoto.length→2)){
txtfilterPhoto3.setText(filterPhoto [2]);
}
}
txtaperturePhoto.setText(aperturePhoto [0]);
如果(aperturePhoto.length→1){
txtaperturePhoto2.setText(aperturePhoto [1]);
如果(aperturePhoto.length→2){
txtaperturePhoto3.setText(aperturePhoto [2]); }
} * / 尝试{
FIS = getApplicationContext()openFileInput(bmImg1);
bmImg1 = BitmapFactory.de codeStream(FIS);
IMAGES.add(bmImg1);
fis.close(); / *
findViewById(R.id.note1).setVisibility(View.VISIBLE);
TextView的descriptionnote =(的TextView)findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto [0]);
* /
如果(numpics→1){
FIS2 = getApplicationContext()openFileInput(bmImg2);
bmImg2 = BitmapFactory.de codeStream(FIS2);
IMAGES.add(bmImg2);
fis2.close();
/ *
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
TextView的descriptionnote2 =(的TextView)findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto [1]);
* / 如果(numpics→2){
fis3 = getApplicationContext()openFileInput(bmImg3);
bmImg3 = BitmapFactory.de codeStream(fis3);
IMAGES.add(bmImg3);
fis3.close();
/ *
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView的descriptionnote3 =(的TextView)findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto [2]);
* /
}
}
}
赶上(FileNotFoundException异常五){
Log.d(TAG,找不到文件);
e.printStackTrace();
}
赶上(IOException异常五){
Log.d(TAGIO异常);
e.printStackTrace();
} PagerAdapter pagerAdapter =新ScreenSlidePagerAdapter(getSupportFragmentManager());
网页=(ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
如果(page.getCurrentItem()== 0){
findViewById(R.id.note1).setVisibility(View.VISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView的descriptionnote =(的TextView)findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto [0]); }
如果(page.getCurrentItem()== 1){
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView的descriptionnote2 =(的TextView)findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto [1]); } 如果(page.getCurrentItem()== 2){
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView的descriptionnote3 =(的TextView)findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto [2]);
}
}@覆盖
公共无效onBack pressed(){
super.onBack pressed();
}@覆盖
公共布尔onOptionsItemSelected(菜单项项){
完();
返回true;
}私有类ScreenSlidePagerAdapter扩展FragmentStatePagerAdapter {
公共ScreenSlidePagerAdapter(FragmentManager FM){
超(FM);
}
公众诠释getItemPosition(对象项){
返回POSITION_NONE;
} @覆盖
公共片段的getItem(INT位置){
ViewPagerFragment片段=新ViewPagerFragment();
fragment.setAsset(IMAGES.get(位置));
返回片段;
} @覆盖
公众诠释的getCount(){
返回IMAGES.size(); }
}}
这是ViewPagerFragment
公共类ViewPagerFragment扩展片段{私有静态最后弦乐BUNDLE_ASSET =资源;私人位图资产;公共ViewPagerFragment(){
}公共无效setAsset(位图资产){
this.asset =资产;
}@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
查看rootView = inflater.inflate(R.layout.view_pager_page,集装箱,FALSE); / *如果(savedInstanceState!= NULL){
如果(资产== NULL和放大器;&安培; savedInstanceState.containsKey(BUNDLE_ASSET)){
资产= savedInstanceState.getParcelable(BUNDLE_ASSET);
}
} * /
如果(资产!= NULL){
SubsamplingScaleImageView的ImageView =(SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(资产)); } 返回rootView;
}@覆盖
公共无效的onSaveInstanceState(捆绑outState){
super.onSaveInstanceState(outState);
查看rootView = getView();
如果(rootView!= NULL){
outState.putString(BUNDLE_ASSET,将String.valueOf(资产));
}
}}
ViewPager.xml
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
< RelativeLayout的
机器人:ID =@ + ID / text1中
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:背景=#333> <网格布局
机器人:ID =@ + ID / suggestedParameter
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:知名度=看得见
机器人:paddingTop =5DP
机器人:paddingLeft =5DP
机器人:paddingRight =5DP
机器人:layout_below =@ + ID / textParameter
机器人:layout_alignParentLeft =真
机器人:layout_alignParentStart =真正的> <的TextView
机器人:ID =@ + ID / shot_levellabel
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ shot_levellabel
机器人:layout_weight =0.10
机器人:比重=中心 机器人:layout_row =0
机器人:layout_column =0
机器人:文字颜色=#FFFFFF/>
<的TextView
机器人:ID =@ + ID / shot_levelsuggested
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:文字颜色=#90c683
机器人:layout_weight =0.10
机器人:layout_row =1
机器人:layout_column =0
机器人:textColorHint =#FFFFFF/>
<的TextView
机器人:ID =@ + ID / shot_levelPhoto
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =2
机器人:layout_column =0
机器人:文字颜色=#FFFFFF
机器人:textColorHint =#FFFFFF/>
<! - <的TextView
机器人:ID =@ + ID / shot_levelPhoto2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =3
机器人:layout_column =0/>
<的TextView
机器人:ID =@ + ID / shot_levelPhoto3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =4
机器人:layout_column =0/> - >
<的TextView
机器人:ID =@ + ID / shutterPhotolabel
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ shutterPhotolabel
机器人:layout_weight =0.10
机器人:layout_row =0
机器人:layout_column =1
机器人:文字颜色=#FFFFFF
机器人:textColorHint =#FFFFFF/> <的TextView
机器人:ID =@ + ID / shutter_suggested
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:文字颜色=#90c683
机器人:layout_weight =0.10
机器人:layout_row =1
机器人:layout_column =1
机器人:textColorHint =#FFFFFF/> <的TextView
机器人:ID =@ + ID / shutterPhoto
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =2
机器人:layout_column =1
机器人:文字颜色=#FFFFFF
机器人:textColorHint =#FFFFFF/>
<! - <的TextView
机器人:ID =@ + ID / shutterPhoto2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =3
机器人:layout_column =1/>
<的TextView
机器人:ID =@ + ID / shutterPhoto3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =4
机器人:layout_column =1/> - >
<的TextView
机器人:ID =@ + ID / aperturePhotolabel
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ aperturePhotolabel
机器人:layout_weight =0.10
机器人:layout_row =0
机器人:layout_column =2
机器人:文字颜色=#FFFFFF/> <的TextView
机器人:ID =@ + ID / aperture_suggested
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:文字颜色=#90c683
机器人:layout_weight =0.10
机器人:layout_row =1
机器人:layout_column =2
机器人:textColorHint =#FFFFFF/> <的TextView
机器人:ID =@ + ID / aperturePhoto
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =2
机器人:layout_column =2
机器人:文字颜色=#FFFFFF
机器人:textColorHint =#FFFFFF/>
<! - <的TextView
机器人:ID =@ + ID / aperturePhoto2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =3
机器人:layout_column =2/>
<的TextView
机器人:ID =@ + ID / aperturePhoto3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =4
机器人:layout_column =2/> - > <的TextView
机器人:ID =@ + ID / isoPhotolabel
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ isoPhotolabel
机器人:layout_weight =0.10
机器人:layout_row =0
机器人:layout_column =3
机器人:文字颜色=#FFFFFF/> <的TextView
机器人:ID =@ + ID / iso_suggested
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:文字颜色=#90c683
机器人:layout_weight =0.10
机器人:layout_row =1
机器人:layout_column =3
机器人:textColorHint =#FFFFFF/> <的TextView
机器人:ID =@ + ID / isoPhoto
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心|权
机器人:layout_weight =0.10
机器人:paddingRight =10dp
机器人:layout_row =2
机器人:layout_column =3
机器人:文字颜色=#FFFFFF
机器人:textColorHint =#FFFFFF/>
<! - <的TextView
机器人:ID =@ + ID / isoPhoto2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心|权
机器人:layout_weight =0.10
机器人:paddingRight =10dp
机器人:layout_row =3
机器人:layout_column =3/>
<的TextView
机器人:ID =@ + ID / isoPhoto3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心|权
机器人:layout_weight =0.10
机器人:paddingRight =10dp
机器人:layout_row =4
机器人:layout_column =3/> - >
<的TextView
机器人:ID =@ + ID / lensPhotolabel
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ lensPhotolabel
机器人:layout_weight =0.10
机器人:layout_row =0
机器人:layout_column =4
机器人:文字颜色=#FFFFFF/>
<的TextView
机器人:ID =@ + ID / lens_suggested
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心|左
机器人:文字颜色=#90c683
机器人:layout_weight =0.10
机器人:layout_row =1
机器人:layout_column =4
机器人:textColorHint =#FFFFFF/> <的TextView
机器人:ID =@ + ID / lensPhoto
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =2
机器人:layout_column =4
机器人:文字颜色=#FFFFFF
机器人:textColorHint =#FFFFFF/>
<! - <的TextView
机器人:ID =@ + ID / lensPhoto2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =3
机器人:layout_column =4
/>
<的TextView
机器人:ID =@ + ID / lensPhoto3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_weight =0.10
机器人:layout_row =4
机器人:layout_column =4
/&GT - →; <的TextView
机器人:ID =@ + ID / filterPhotolabel
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ filterPhotolabel
机器人:layout_weight =0.10
机器人:layout_row =0
机器人:layout_column =5
机器人:文字颜色=#FFFFFF/> <的TextView
机器人:ID =@ + ID / filter_suggested
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:文字颜色=#90c683
机器人:layout_row =1
机器人:layout_column =5
机器人:textColorHint =#FFFFFF/> <的TextView
机器人:ID =@ + ID / filterPhoto
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_row =2
机器人:layout_column =5
机器人:文字颜色=#FFFFFF
机器人:textColorHint =#FFFFFF/>
<! - <的TextView
机器人:ID =@ + ID / filterPhoto2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_row =3
机器人:layout_column =5
/>
<的TextView
机器人:ID =@ + ID / filterPhoto3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:提示=无
机器人:比重=中心
机器人:layout_row =4
机器人:layout_column =5
/&GT - →;
< /网格布局> <! - <的TextView
机器人:ID =@ + ID / parameter_suggested
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =match_parent
机器人:填充=10dp
机器人:TEXTSIZE =14sp
机器人:文字颜色=#FFFFFF
机器人:知名度=看得见
/>
<的TextView
机器人:ID =@ + ID /参数2
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =match_parent
机器人:填充=10dp
机器人:TEXTSIZE =14sp
机器人:文字颜色=#FFFFFF
机器人:知名度=隐形
机器人:文字=456
机器人:layout_below =@ + ID / parameter_suggested
/> <的TextView
机器人:ID =@ + ID /参数3
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =match_parent
机器人:填充=10dp
机器人:TEXTSIZE =14sp
机器人:文字颜色=#FFFFFF
机器人:知名度=看得见
机器人:文字=789
机器人:layout_below =@ + ID / parameter_suggested
/>
- >< / RelativeLayout的>< RelativeLayout的
机器人:ID =@ + ID /文
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentBottom =真
机器人:背景=#333> <的TextView
机器人:ID =@ + ID /注1
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =match_parent
机器人:填充=10dp
机器人:TEXTSIZE =14sp
机器人:文字颜色=#FFFFFF
机器人:知名度=隐形
/>
<的TextView
机器人:ID =@ + ID /注2
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =match_parent
机器人:填充=10dp
机器人:TEXTSIZE =14sp
机器人:文字颜色=#FFFFFF
机器人:知名度=隐形
/>
<的TextView
机器人:ID =@ + ID /注3
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =match_parent
机器人:填充=10dp
机器人:TEXTSIZE =14sp
机器人:文字颜色=#FFFFFF
机器人:知名度=隐形
/>< / RelativeLayout的>< android.support.v4.view.ViewPager
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID /寻呼机
机器人:layout_above =@ ID /文
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ + ID /文本1/>
< / RelativeLayout的>
挣扎,读这么多不同的解决方案,我固定由我自己的问题之后。
我想与大家分享我的解决方案或许可以帮助别人。
随意问我关于它的一切。
这是FragmentActivity:
公共类ViewPagerActivity扩展FragmentActivity {私人布尔再次= FALSE;
私人ViewPager页面;
私人位图bmImg1;
私人位图bmImg2;
私人位图bmImg3;
私人字符串标记;
ArrayList的<&位图GT; IMAGES =新的ArrayList<>();
ArrayList的<串GT;记述=新的ArrayList<>();
ArrayList的<串GT; SHOTLEVEL =新的ArrayList<>();
ArrayList的<串GT; FILTERPHOTO =新的ArrayList<>();
ArrayList的<串GT; APERTUREPHOTO =新的ArrayList<>();
ArrayList的<串GT; SHUTTERPHOTO =新的ArrayList<>();
ArrayList的<串GT; ISOPHOTO =新的ArrayList<>();
ArrayList的<串GT; LENSPHOTO =新的ArrayList<>();的String [] descriptionPhoto;
私人字符串shot_levelPhoto;
私人字符串shot_levelPhoto1;
私人字符串shot_levelPhoto2;私人字符串filterPhoto;
私人字符串filterPhoto1;
私人字符串filterPhoto2;私人字符串aperturePhoto;
私人字符串aperturePhoto1;
私人字符串aperturePhoto2;私人字符串shutterPhoto;
私人字符串shutterPhoto1;
私人字符串shutterPhoto2;私人字符串isoPhoto;
私人字符串isoPhoto1;
私人字符串isoPhoto2;私人字符串focal_lengthPhoto;
私人字符串focal_lengthPhoto1;
私人字符串focal_lengthPhoto2;私有String [] = shot_levelPhotoArray新的String [3];
私有String [] = filterPhotoArray新的String [3];
私有String [] = aperturePhotoArray新的String [3];
私有String [] = shutterPhotoArray新的String [3];
私有String [] = isoPhotoArray新的String [3];
私有String [] = focal_lengthPhotoArray新的String [3];INT numpics = 1;
私人诠释position_pic;
私人字符串suggested_aperture;
私人字符串suggested_filter;
私人字符串suggested_iso;
私人字符串suggested_shutter;
私人字符串suggested_shot_level;
私人字符串suggested_lens;私人LayoutInflater吹气;
私人布尔firsttime;
私人布尔secondtime;
私人INT oldposition = 0;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.view_pager);
FIS的FileInputStream;
的FileInputStream FIS2;
的FileInputStream fis3;
捆绑意图= getIntent()getExtras()。
descriptionPhoto = intent.getStringArray(descriptionPhoto); numpics =(int)的intent.get(numpics);
position_pic =(int)的intent.get(position_pic); suggested_aperture = intent.getString(suggested_aperture);
suggested_filter = intent.getString(suggested_filter);
suggested_iso = intent.getString(suggested_iso);
suggested_shutter = intent.getString(suggested_shutter);
suggested_shot_level = intent.getString(suggested_shot_level);
suggested_lens = intent.getString(suggested_lens); shot_levelPhoto = intent.getString(shot_levelPhoto);
shot_levelPhoto1 = intent.getString(shot_levelPhoto1);
shot_levelPhoto2 = intent.getString(shot_levelPhoto2); shot_levelPhotoArray [0] = shot_levelPhoto;
如果(!shot_levelPhoto1.equals(空)){
shot_levelPhotoArray [1] = shot_levelPhoto1;
如果(!shot_levelPhoto2.equals(空)){
shot_levelPhotoArray [2] = shot_levelPhoto2;
}
} filterPhoto = intent.getString(filterPhoto);
filterPhoto1 = intent.getString(filterPhoto1);
filterPhoto2 = intent.getString(filterPhoto2);
filterPhotoArray [0] = filterPhoto;
如果(!filterPhoto1.equals(空)){
filterPhotoArray [1] = filterPhoto1;
如果(!filterPhoto2.equals(空)){
filterPhotoArray [2] = filterPhoto2;
}
} aperturePhoto = intent.getString(aperturePhoto);
aperturePhoto1 = intent.getString(aperturePhoto1);
aperturePhoto2 = intent.getString(aperturePhoto2);
aperturePhotoArray [0] = aperturePhoto;
如果(!aperturePhoto1.equals(空)){
aperturePhotoArray [1] = aperturePhoto1;
如果(!aperturePhoto2.equals(空)){
aperturePhotoArray [2] = aperturePhoto2;
}
} shutterPhoto = intent.getString(shutterPhoto);
shutterPhoto1 = intent.getString(shutterPhoto1);
shutterPhoto2 = intent.getString(shutterPhoto2);
shutterPhotoArray [0] = shutterPhoto;
如果(!shutterPhoto1.equals(空)){
shutterPhotoArray [1] = shutterPhoto1;
如果(!shutterPhoto2.equals(空)){
shutterPhotoArray [2] = shutterPhoto2;
}
} isoPhoto = intent.getString(isoPhoto);
isoPhoto1 = intent.getString(isoPhoto1);
isoPhoto2 = intent.getString(isoPhoto2);
isoPhotoArray [0] = isoPhoto;
如果(!isoPhoto1.equals(空)){
isoPhotoArray [1] = isoPhoto1;
如果(!isoPhoto2.equals(空)){
isoPhotoArray [2] = isoPhoto2;
}
} focal_lengthPhoto = intent.getString(focal_lengthPhoto);
focal_lengthPhoto1 = intent.getString(focal_lengthPhoto1);
focal_lengthPhoto2 = intent.getString(focal_lengthPhoto2);
focal_lengthPhotoArray [0] = focal_lengthPhoto;
如果(!focal_lengthPhoto1.equals(空)){
focal_lengthPhotoArray [1] = focal_lengthPhoto1;
如果(!focal_lengthPhoto2.equals(空)){
focal_lengthPhotoArray [2] = focal_lengthPhoto2;
}
}
TextView的txtaperture_suggested =(的TextView)findViewById(R.id.aperture_suggested);
TextView的txtfilter_suggested =(的TextView)findViewById(R.id.filter_suggested);
TextView的txtiso_suggested =(的TextView)findViewById(R.id.iso_suggested);
TextView的txtlens_suggested =(的TextView)findViewById(R.id.lens_suggested);
TextView的txtshutter_suggested =(的TextView)findViewById(R.id.shutter_suggested);
TextView的txtshot_levelsuggested =(的TextView)findViewById(R.id.shot_levelsuggested); 如果(suggested_shot_level ==1){
txtshot_levelsuggested.setText(易); }否则如果(suggested_shot_level ==2){
txtshot_levelsuggested.setText(中); }否则如果(suggested_shot_level ==3){
txtshot_levelsuggested.setText(难); }否则如果(suggested_shot_level ==4){
txtshot_levelsuggested.setText(临); } txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens); / *的TextView txtshutterPhoto =(的TextView)findViewById(R.id.shutterPhoto);
TextView的txtshutterPhoto2 =(的TextView)findViewById(R.id.shutterPhoto2);
TextView的txtshutterPhoto3 =(的TextView)findViewById(R.id.shutterPhoto3); TextView的txtshot_levelPhoto =(的TextView)findViewById(R.id.shot_levelPhoto);
TextView的txtshot_levelPhoto2 =(的TextView)findViewById(R.id.shot_levelPhoto2);
TextView的txtshot_levelPhoto3 =(的TextView)findViewById(R.id.shot_levelPhoto3); TextView的txtaperturePhoto =(的TextView)findViewById(R.id.aperturePhoto);
TextView的txtaperturePhoto2 =(的TextView)findViewById(R.id.aperturePhoto2);
TextView的txtaperturePhoto3 =(的TextView)findViewById(R.id.aperturePhoto3); TextView的txtfilterPhoto =(的TextView)findViewById(R.id.filterPhoto);
TextView的txtfilterPhoto2 =(的TextView)findViewById(R.id.filterPhoto2);
TextView的txtfilterPhoto3 =(的TextView)findViewById(R.id.filterPhoto3); TextView的txtisoPhoto =(的TextView)findViewById(R.id.isoPhoto);
TextView的txtisoPhoto2 =(的TextView)findViewById(R.id.isoPhoto2);
TextView的txtisoPhoto3 =(的TextView)findViewById(R.id.isoPhoto3); TextView的txtfocal_lengthPhoto =(的TextView)findViewById(R.id.lensPhoto);
TextView的txtfocal_lengthPhoto2 =(的TextView)findViewById(R.id.lensPhoto2);
TextView的txtfocal_lengthPhoto3 =(的TextView)findViewById(R.id.lensPhoto3); * / / *如果(shot_levelPhotoArray [0] ==1){
txtshot_levelPhoto.setText(易);
shot_levelPhotoArray [0] =易;
* // * txtshot_levelPhoto2.setText(易);
txtshot_levelPhoto3.setText(易); // * * }否则如果(shot_levelPhotoArray [0] ==2){
txtshot_levelPhoto.setText(中);
shot_levelPhotoArray [0] =中等;
* // * txtshot_levelPhoto2.setText(中);
txtshot_levelPhoto3.setText(中); // * *
}否则如果(shot_levelPhotoArray [0] ==3){
txtshot_levelPhoto.setText(难);
shot_levelPhotoArray [0] =难;
* // * txtshot_levelPhoto2.setText(难);
txtshot_levelPhoto3.setText(难); // * *
}其他{
txtshot_levelPhoto.setText(临);
shot_levelPhotoArray [0] =亲;
* // * txtshot_levelPhoto2.setText(临);
txtshot_levelPhoto3.setText(临); // * *
}
txtshutterPhoto.setText(shutterPhoto);
txtisoPhoto.setText(isoPhoto);
txtfilterPhoto.setText(filterPhoto);
txtaperturePhoto.setText(aperturePhoto);
txtfocal_lengthPhoto.setText(focal_lengthPhoto); * /
/*txtshutterPhoto.setText(shutterPhoto[0]);
如果(shutterPhoto.length→1){
txtshutterPhoto2.setText(shutterPhoto [1]);
如果(shutterPhoto.length→2){
txtshutterPhoto3.setText(shutterPhoto [2]); }
}
txtisoPhoto.setText(isoPhoto [0]);
如果(isoPhoto.length→1){
txtisoPhoto2.setText(isoPhoto [1]);
如果(isoPhoto.length→2){
txtisoPhoto3.setText(isoPhoto [2]);
}
}
txtfilterPhoto.setText(filterPhoto [0]);
如果(filterPhoto.length→1){
txtfilterPhoto2.setText(filterPhoto [1]);
如果((filterPhoto.length→2)){
txtfilterPhoto3.setText(filterPhoto [2]);
}
}
txtaperturePhoto.setText(aperturePhoto [0]);
如果(aperturePhoto.length→1){
txtaperturePhoto2.setText(aperturePhoto [1]);
如果(aperturePhoto.length→2){
txtaperturePhoto3.setText(aperturePhoto [2]); }
} * / 尝试{
FIS = getApplicationContext()openFileInput(bmImg1);
bmImg1 = BitmapFactory.de codeStream(FIS);
IMAGES.add(bmImg1);
DESCRIPTIONS.add(descriptionPhoto [0]);
SHOTLEVEL.add(shot_levelPhotoArray [0]);
FILTERPHOTO.add(filterPhotoArray [0]);
APERTUREPHOTO.add(aperturePhotoArray [0]);
SHUTTERPHOTO.add(shutterPhotoArray [0]);
ISOPHOTO.add(isoPhotoArray [0]);
LENSPHOTO.add(focal_lengthPhotoArray [0]);
fis.close(); 如果(numpics→1){
FIS2 = getApplicationContext()openFileInput(bmImg2);
bmImg2 = BitmapFactory.de codeStream(FIS2);
IMAGES.add(bmImg2);
DESCRIPTIONS.add(descriptionPhoto [1]);
SHOTLEVEL.add(shot_levelPhotoArray [1]);
FILTERPHOTO.add(filterPhotoArray [1]);
APERTUREPHOTO.add(aperturePhotoArray [1]);
SHUTTERPHOTO.add(shutterPhotoArray [1]);
ISOPHOTO.add(isoPhotoArray [1]);
LENSPHOTO.add(focal_lengthPhotoArray [1]);
fis2.close();
如果(numpics→2){
fis3 = getApplicationContext()openFileInput(bmImg3);
bmImg3 = BitmapFactory.de codeStream(fis3);
IMAGES.add(bmImg3);
DESCRIPTIONS.add(descriptionPhoto [2]);
SHOTLEVEL.add(shot_levelPhotoArray [2]);
FILTERPHOTO.add(filterPhotoArray [2]);
APERTUREPHOTO.add(aperturePhotoArray [2]);
SHUTTERPHOTO.add(shutterPhotoArray [2]);
ISOPHOTO.add(isoPhotoArray [2]);
LENSPHOTO.add(focal_lengthPhotoArray [2]);
fis3.close();
}
}
}
赶上(FileNotFoundException异常五){
Log.d(TAG,找不到文件);
e.printStackTrace();
}
赶上(IOException异常五){
Log.d(TAGIO异常);
e.printStackTrace();
} PagerAdapter pagerAdapter =新ScreenSlidePagerAdapter(getSupportFragmentManager(),descriptionPhoto [position_pic]);
网页=(ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
}
@覆盖
公共无效onBack pressed(){
super.onBack pressed();
}
公共无效清除(){
IMAGES.clear();
DESCRIPTIONS.clear();
SHOTLEVEL.clear();
FILTERPHOTO.clear();
APERTUREPHOTO.clear();
SHUTTERPHOTO.clear();
ISOPHOTO.clear();
LENSPHOTO.clear();
}@覆盖
公共布尔onOptionsItemSelected(菜单项项){
完();
返回true;
}私有类ScreenSlidePagerAdapter扩展FragmentStatePagerAdapter { 字符串描述; 公共ScreenSlidePagerAdapter(FragmentManager FM,字符串描述){
超(FM);
this.description =描述;
}
@覆盖
公共无效destroyItem(ViewGroup中的容器,INT位置,Object对象){
super.destroyItem(集装箱,位置,对象);
} // notifyDataSetChanged时(这就是所谓的)被称为
@覆盖
公众诠释getItemPosition(Object对象){
//刷新所有片段时,数据集改变
返回PagerAdapter.POSITION_NONE;
} @覆盖
公共布尔isViewFromObject(查看视图,Object对象){
如果(对象!= NULL){
返回((片段)对象).getView()==视图。
}其他{
返回false; }
} / * @覆盖
公共片段的getItem(INT位置){
ViewPagerFragment片段=新ViewPagerFragment();
fragment.setAsset(IMAGES.get(位置));
返回片段;
} * / @覆盖
公共片段的getItem(INT指数){
ViewPagerFragment片段=新ViewPagerFragment();
//fragment.setAsset(IMAGES.get(index));
fragment.setAsset(IMAGES.get(指数),DESCRIPTIONS.get(指数));
ViewPagerFragment.newInstance(指数,
SHOTLEVEL.get(指数),
FILTERPHOTO.get(指数),
APERTUREPHOTO.get(指数),
SHUTTERPHOTO.get(指数),
ISOPHOTO.get(指数),
LENSPHOTO.get(索引)); // Pages是一个字符串数组
返回片段; } @覆盖
公众诠释的getCount(){
返回IMAGES.size();
}}
}
这是片断
公共类ViewPagerFragment扩展片段{私有静态最后弦乐BUNDLE_ASSET =资源;私人位图资产;串descriptionPhoto;
私人TextView的电视;HashMap的<位图,字符串>地图;
私有静态束束;
公共ViewPagerFragment(){
}/ *公众诠释setAsset(位图资产){
this.asset =资产; 返回0;
} * /公众的HashMap<位图,字符串> setAsset(位图资产,字符串描述){
地图=新的HashMap<>();
this.asset =资产;
this.descriptionPhoto =描述; map.put(this.asset,this.descriptionPhoto);
返回地图;
}@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
}
@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
查看rootView = inflater.inflate(R.layout.view_pager_page,集装箱,FALSE); 如果(savedInstanceState!= NULL){
如果(资产== NULL和放大器;&安培; savedInstanceState.containsKey(BUNDLE_ASSET)){
资产= savedInstanceState.getParcelable(BUNDLE_ASSET);
}
}
如果(资产= NULL&放大器;!&安培;!descriptionPhoto = NULL){
TextView的descriptionnote =(TextView中)rootView.findViewById(R.id.note1);
如果(descriptionPhoto.equals(空)){
descriptionPhoto =没有找到图片说明;
}
descriptionnote.setText(descriptionPhoto);
SubsamplingScaleImageView的ImageView =(SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(资产));
TextView的txtshot_level =(TextView中)rootView.findViewById(R.id.shot_levelPhoto);
TextView的txtshutterPhoto =(TextView中)rootView.findViewById(R.id.shutterPhoto);
TextView的txtaperturePhoto =(TextView中)rootView.findViewById(R.id.aperturePhoto);
TextView的txtfilterPhoto =(TextView中)rootView.findViewById(R.id.filterPhoto);
TextView的txtisoPhoto =(TextView中)rootView.findViewById(R.id.isoPhoto);
TextView的txtfocal_lengthPhoto =(TextView中)rootView.findViewById(R.id.lensPhoto); txtshot_level.setText(bundle.getString(shot_levelcontent));
txtshutterPhoto.setText(bundle.getString(shuttercontent));
txtisoPhoto.setText(bundle.getString(isocontent));
txtfilterPhoto.setText(bundle.getString(filtercontent));
txtaperturePhoto.setText(bundle.getString(aperturecontent));
txtfocal_lengthPhoto.setText(bundle.getString(lenscontent)); }
返回rootView;
}@覆盖
公共无效的onSaveInstanceState(捆绑outState){
super.onSaveInstanceState(outState);
查看rootView = getView();
如果(rootView!= NULL){
outState.putString(BUNDLE_ASSET,将String.valueOf(资产));
}
}
公共静态的newInstance片段(INT位置,
串shot_level,
字符串过滤器,
串光圈,
串快门,
串异,
串镜头){
ViewPagerFragment swipeFragment =新ViewPagerFragment();
捆绑=新包();
如果(shot_level.equals(1)){
bundle.putString(shot_levelcontent,易); }否则如果(shot_level.equals(2)){
bundle.putString(shot_levelcontent,中); }否则如果(shot_level.equals(3)){
bundle.putString(shot_levelcontent,难);
}其他{
bundle.putString(shot_levelcontent,亲);
}
bundle.putString(filtercontent过滤器);
bundle.putString(aperturecontent,口径);
bundle.putString(shuttercontent,卷帘);
bundle.putString(isocontent,异);
bundle.putString(lenscontent透镜);
swipeFragment.setArguments(包);
返回swipeFragment;}
}
I've been looking around but I can't figure out how I can fixed this issue. I'm using the @Dave Morrissey's Subsampling Zoom Image View, is a great library and it works perfect, but I want to do a few changes. For each image that the user will slide I want show the specific description. So it will be:
Pic1 |Pic2 |Pic3
DescriptionPic1 |DescriptionPic2 |DescriptionPic3
When I open it I can see the picture with below the right description but when I slide left(or right) I can see always the description of the item after. Happens because the method getItem() get called twice to make the slider more smooth. The problem is that I want show the right content(description) below each picture. How can I show the content perfectly when the user slide the pics? Any help is really appreciate. Thanks guys ViewPagerActivity.java
public class ViewPagerActivity extends FragmentActivity {
private ViewPager page;
private Bitmap bmImg1;
private Bitmap bmImg2;
private Bitmap bmImg3;
private String TAG;
ArrayList<Bitmap> IMAGES =new ArrayList<Bitmap>();
String[] descriptionPhoto;
int numpics=1;
private int position_pic;
private String suggested_aperture;
private String suggested_filter;
private String suggested_iso;
private String suggested_shutter;
private String suggested_shot_level;
private String suggested_lens;
private String[] shot_levelPhoto;
private String[] filterPhoto;
private String[] aperturePhoto;
private String[] shutterPhoto;
private String[] isoPhoto;
private String[] focal_lengthPhoto;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager);
FileInputStream fis;
FileInputStream fis2;
FileInputStream fis3;
Bundle intent=getIntent().getExtras();
descriptionPhoto = intent.getStringArray("descriptionPhoto");
numpics = (int) intent.get("numpics");
position_pic = (int) intent.get("position_pic");
suggested_aperture= intent.getString("suggested_aperture");
suggested_filter= intent.getString("suggested_filter");
suggested_iso= intent.getString("suggested_iso");
suggested_shutter= intent.getString("suggested_shutter");
suggested_shot_level= intent.getString("suggested_shot_level");
suggested_lens= intent.getString("suggested_lens");
shot_levelPhoto=intent.getStringArray("shot_levelPhoto");
filterPhoto =intent.getStringArray("filterPhoto");
aperturePhoto =intent.getStringArray("aperturePhoto");
shutterPhoto =intent.getStringArray("shutterPhoto");
isoPhoto =intent.getStringArray("isoPhoto");
focal_lengthPhoto=intent.getStringArray("focal_lengthPhoto");
TextView txtaperture_suggested = (TextView) findViewById(R.id.aperture_suggested);
TextView txtfilter_suggested = (TextView) findViewById(R.id.filter_suggested);
TextView txtiso_suggested = (TextView) findViewById(R.id.iso_suggested);
TextView txtlens_suggested = (TextView) findViewById(R.id.lens_suggested);
TextView txtshutter_suggested = (TextView) findViewById(R.id.shutter_suggested);
TextView txtshot_levelsuggested = (TextView) findViewById(R.id.shot_levelsuggested);
if (suggested_shot_level == "1") {
txtshot_levelsuggested.setText("Easy");
/*txtshot_levelPhoto2.setText("Easy");
txtshot_levelPhoto3.setText("Easy");*/
} else if (suggested_shot_level == "2") {
txtshot_levelsuggested.setText("Medium");
/* txtshot_levelPhoto2.setText("Medium");
txtshot_levelPhoto3.setText("Medium");*/
} else if (suggested_shot_level == "3") {
txtshot_levelsuggested.setText("Difficult");
/*txtshot_levelPhoto2.setText("Difficult");
txtshot_levelPhoto3.setText("Difficult");*/
} else {
txtshot_levelsuggested.setText("Pro");
/* txtshot_levelPhoto2.setText("Pro");
txtshot_levelPhoto3.setText("Pro");*/
}
txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens);
TextView txtshutterPhoto = (TextView) findViewById(R.id.shutterPhoto);
TextView txtshutterPhoto2 = (TextView) findViewById(R.id.shutterPhoto2);
TextView txtshutterPhoto3 = (TextView) findViewById(R.id.shutterPhoto3);
TextView txtshot_levelPhoto = (TextView) findViewById(R.id.shot_levelPhoto);
TextView txtshot_levelPhoto2 = (TextView) findViewById(R.id.shot_levelPhoto2);
TextView txtshot_levelPhoto3 = (TextView) findViewById(R.id.shot_levelPhoto3);
TextView txtaperturePhoto = (TextView) findViewById(R.id.aperturePhoto);
TextView txtaperturePhoto2 = (TextView) findViewById(R.id.aperturePhoto2);
TextView txtaperturePhoto3 = (TextView) findViewById(R.id.aperturePhoto3);
TextView txtfilterPhoto = (TextView) findViewById(R.id.filterPhoto);
TextView txtfilterPhoto2 = (TextView) findViewById(R.id.filterPhoto2);
TextView txtfilterPhoto3 = (TextView) findViewById(R.id.filterPhoto3);
TextView txtisoPhoto = (TextView) findViewById(R.id.isoPhoto);
TextView txtisoPhoto2 = (TextView) findViewById(R.id.isoPhoto2);
TextView txtisoPhoto3 = (TextView) findViewById(R.id.isoPhoto3);
TextView txtlensPhoto = (TextView) findViewById(R.id.lensPhoto);
TextView txtlensPhoto2 = (TextView) findViewById(R.id.lensPhoto2);
TextView txtlensPhoto3 = (TextView) findViewById(R.id.lensPhoto3);
/*txtshutterPhoto.setText(shutterPhoto[0]);
if (shutterPhoto.length > 1) {
txtshutterPhoto2.setText(shutterPhoto[1]);
if (shutterPhoto.length > 2) {
txtshutterPhoto3.setText(shutterPhoto[2]);
}
}
txtisoPhoto.setText(isoPhoto[0]);
if (isoPhoto.length > 1) {
txtisoPhoto2.setText(isoPhoto[1]);
if (isoPhoto.length > 2) {
txtisoPhoto3.setText(isoPhoto[2]);
}
}
txtfilterPhoto.setText(filterPhoto[0]);
if (filterPhoto.length > 1) {
txtfilterPhoto2.setText(filterPhoto[1]);
if ((filterPhoto.length > 2)) {
txtfilterPhoto3.setText(filterPhoto[2]);
}
}
txtaperturePhoto.setText(aperturePhoto[0]);
if (aperturePhoto.length > 1) {
txtaperturePhoto2.setText(aperturePhoto[1]);
if (aperturePhoto.length > 2) {
txtaperturePhoto3.setText(aperturePhoto[2]);
}
}*/
try {
fis = getApplicationContext().openFileInput("bmImg1");
bmImg1 = BitmapFactory.decodeStream(fis);
IMAGES.add(bmImg1);
fis.close();
/*
findViewById(R.id.note1).setVisibility(View.VISIBLE);
TextView descriptionnote = (TextView)findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto[0]);
*/
if(numpics>1){
fis2 = getApplicationContext().openFileInput("bmImg2");
bmImg2 = BitmapFactory.decodeStream(fis2);
IMAGES.add(bmImg2);
fis2.close();
/*
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
TextView descriptionnote2 = (TextView)findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto[1]);
*/
if(numpics>2){
fis3 = getApplicationContext().openFileInput("bmImg3");
bmImg3 = BitmapFactory.decodeStream(fis3);
IMAGES.add(bmImg3);
fis3.close();
/*
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView descriptionnote3 = (TextView)findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto[2]);
*/
}
}
}
catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
}
catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
page = (ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
if(page.getCurrentItem()==0 ){
findViewById(R.id.note1).setVisibility(View.VISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView descriptionnote = (TextView) findViewById(R.id.note1);
descriptionnote.setText(descriptionPhoto[0]);
}
if (page.getCurrentItem()==1 ) {
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.VISIBLE);
findViewById(R.id.note3).setVisibility(View.INVISIBLE);
TextView descriptionnote2 = (TextView) findViewById(R.id.note2);
descriptionnote2.setText(descriptionPhoto[1]);
}
if (page.getCurrentItem()==2 ) {
findViewById(R.id.note1).setVisibility(View.INVISIBLE);
findViewById(R.id.note2).setVisibility(View.INVISIBLE);
findViewById(R.id.note3).setVisibility(View.VISIBLE);
TextView descriptionnote3 = (TextView) findViewById(R.id.note3);
descriptionnote3.setText(descriptionPhoto[2]);
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
public int getItemPosition(Object item){
return POSITION_NONE;
}
@Override
public Fragment getItem(int position) {
ViewPagerFragment fragment = new ViewPagerFragment();
fragment.setAsset(IMAGES.get(position));
return fragment;
}
@Override
public int getCount() {
return IMAGES.size();
}
}}
This is the ViewPagerFragment
public class ViewPagerFragment extends Fragment {
private static final String BUNDLE_ASSET = "res";
private Bitmap asset;
public ViewPagerFragment() {
}
public void setAsset(Bitmap asset) {
this.asset = asset;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.view_pager_page, container, false);
/* if (savedInstanceState != null) {
if (asset == null && savedInstanceState.containsKey(BUNDLE_ASSET)) {
asset = savedInstanceState.getParcelable(BUNDLE_ASSET);
}
}*/
if (asset != null) {
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(asset));
}
return rootView;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
View rootView = getView();
if (rootView != null) {
outState.putString(BUNDLE_ASSET, String.valueOf(asset));
}
}}
ViewPager.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#333">
<GridLayout
android:id="@+id/suggestedParameter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible"
android:paddingTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_below="@+id/textParameter"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="@+id/shot_levellabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shot_levellabel"
android:layout_weight="0.10"
android:gravity="center"
android:layout_row="0"
android:layout_column="0"
android:textColor="#ffffff" />
<TextView
android:id="@+id/shot_levelsuggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="0"
android:textColorHint="#ffffff" />
<TextView
android:id="@+id/shot_levelPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="0"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="@+id/shot_levelPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="0" />
<TextView
android:id="@+id/shot_levelPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="0" />-->
<TextView
android:id="@+id/shutterPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shutterPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="1"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<TextView
android:id="@+id/shutter_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="1"
android:textColorHint="#ffffff" />
<TextView
android:id="@+id/shutterPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="1"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="@+id/shutterPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="1" />
<TextView
android:id="@+id/shutterPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="1" />-->
<TextView
android:id="@+id/aperturePhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/aperturePhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="2"
android:textColor="#ffffff" />
<TextView
android:id="@+id/aperture_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="2"
android:textColorHint="#ffffff" />
<TextView
android:id="@+id/aperturePhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="2"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="@+id/aperturePhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="2" />
<TextView
android:id="@+id/aperturePhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="2" />-->
<TextView
android:id="@+id/isoPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/isoPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="3"
android:textColor="#ffffff" />
<TextView
android:id="@+id/iso_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="3"
android:textColorHint="#ffffff" />
<TextView
android:id="@+id/isoPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="2"
android:layout_column="3"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="@+id/isoPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="3"
android:layout_column="3" />
<TextView
android:id="@+id/isoPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|right"
android:layout_weight="0.10"
android:paddingRight="10dp"
android:layout_row="4"
android:layout_column="3" />-->
<TextView
android:id="@+id/lensPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/lensPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="4"
android:textColor="#ffffff" />
<TextView
android:id="@+id/lens_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center|left"
android:textColor="#90c683"
android:layout_weight="0.10"
android:layout_row="1"
android:layout_column="4"
android:textColorHint="#ffffff" />
<TextView
android:id="@+id/lensPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="2"
android:layout_column="4"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="@+id/lensPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="3"
android:layout_column="4"
/>
<TextView
android:id="@+id/lensPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_weight="0.10"
android:layout_row="4"
android:layout_column="4"
/>-->
<TextView
android:id="@+id/filterPhotolabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/filterPhotolabel"
android:layout_weight="0.10"
android:layout_row="0"
android:layout_column="5"
android:textColor="#ffffff" />
<TextView
android:id="@+id/filter_suggested"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:textColor="#90c683"
android:layout_row="1"
android:layout_column="5"
android:textColorHint="#ffffff" />
<TextView
android:id="@+id/filterPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="2"
android:layout_column="5"
android:textColor="#ffffff"
android:textColorHint="#ffffff" />
<!-- <TextView
android:id="@+id/filterPhoto2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="3"
android:layout_column="5"
/>
<TextView
android:id="@+id/filterPhoto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint=" None"
android:gravity="center"
android:layout_row="4"
android:layout_column="5"
/>-->
</GridLayout>
<!--<TextView
android:id="@+id/parameter_suggested"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="visible"
/>
<TextView
android:id="@+id/parameter2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
android:text="456"
android:layout_below="@+id/parameter_suggested"
/>
<TextView
android:id="@+id/parameter3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="visible"
android:text="789"
android:layout_below="@+id/parameter_suggested"
/>
-->
</RelativeLayout>
<RelativeLayout
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#333">
<TextView
android:id="@+id/note1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
<TextView
android:id="@+id/note2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
<TextView
android:id="@+id/note3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
android:textSize="14sp"
android:textColor="#FFFFFF"
android:visibility="invisible"
/>
</RelativeLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_above="@id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/text1" />
</RelativeLayout>
After struggling and reading so many different solutions I fixed by myself the issue. I wanted share with you my solutions maybe can help someone else. Feel free to ask me everything about it.
This is the FragmentActivity:
public class ViewPagerActivity extends FragmentActivity {
private boolean again=false;
private ViewPager page;
private Bitmap bmImg1;
private Bitmap bmImg2;
private Bitmap bmImg3;
private String TAG;
ArrayList<Bitmap> IMAGES =new ArrayList<>();
ArrayList<String> DESCRIPTIONS =new ArrayList<>();
ArrayList<String> SHOTLEVEL=new ArrayList<>();
ArrayList<String> FILTERPHOTO=new ArrayList<>();
ArrayList<String> APERTUREPHOTO=new ArrayList<>();
ArrayList<String> SHUTTERPHOTO=new ArrayList<>();
ArrayList<String> ISOPHOTO=new ArrayList<>();
ArrayList<String> LENSPHOTO=new ArrayList<>();
String[] descriptionPhoto;
private String shot_levelPhoto;
private String shot_levelPhoto1;
private String shot_levelPhoto2;
private String filterPhoto;
private String filterPhoto1;
private String filterPhoto2;
private String aperturePhoto;
private String aperturePhoto1;
private String aperturePhoto2;
private String shutterPhoto;
private String shutterPhoto1;
private String shutterPhoto2;
private String isoPhoto;
private String isoPhoto1;
private String isoPhoto2;
private String focal_lengthPhoto;
private String focal_lengthPhoto1;
private String focal_lengthPhoto2;
private String[] shot_levelPhotoArray= new String[3];
private String[] filterPhotoArray= new String[3];
private String[] aperturePhotoArray=new String[3];
private String[] shutterPhotoArray=new String[3];
private String[] isoPhotoArray=new String[3];
private String[] focal_lengthPhotoArray=new String[3];
int numpics=1;
private int position_pic;
private String suggested_aperture;
private String suggested_filter;
private String suggested_iso;
private String suggested_shutter;
private String suggested_shot_level;
private String suggested_lens;
private LayoutInflater inflater;
private boolean firsttime;
private boolean secondtime;
private int oldposition=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_pager);
FileInputStream fis;
FileInputStream fis2;
FileInputStream fis3;
Bundle intent=getIntent().getExtras();
descriptionPhoto = intent.getStringArray("descriptionPhoto");
numpics = (int) intent.get("numpics");
position_pic = (int) intent.get("position_pic");
suggested_aperture= intent.getString("suggested_aperture");
suggested_filter= intent.getString("suggested_filter");
suggested_iso= intent.getString("suggested_iso");
suggested_shutter= intent.getString("suggested_shutter");
suggested_shot_level= intent.getString("suggested_shot_level");
suggested_lens= intent.getString("suggested_lens");
shot_levelPhoto=intent.getString("shot_levelPhoto");
shot_levelPhoto1=intent.getString("shot_levelPhoto1");
shot_levelPhoto2=intent.getString("shot_levelPhoto2");
shot_levelPhotoArray[0] = shot_levelPhoto;
if(!shot_levelPhoto1.equals("null")){
shot_levelPhotoArray[1]=shot_levelPhoto1;
if(!shot_levelPhoto2.equals("null")){
shot_levelPhotoArray[2]=shot_levelPhoto2;
}
}
filterPhoto =intent.getString("filterPhoto");
filterPhoto1 =intent.getString("filterPhoto1");
filterPhoto2 =intent.getString("filterPhoto2");
filterPhotoArray[0]= filterPhoto;
if(!filterPhoto1.equals("null")){
filterPhotoArray[1]=filterPhoto1;
if(!filterPhoto2.equals("null")){
filterPhotoArray[2]=filterPhoto2;
}
}
aperturePhoto =intent.getString("aperturePhoto");
aperturePhoto1 =intent.getString("aperturePhoto1");
aperturePhoto2 =intent.getString("aperturePhoto2");
aperturePhotoArray[0]= aperturePhoto;
if(!aperturePhoto1.equals("null")){
aperturePhotoArray[1]=aperturePhoto1;
if(!aperturePhoto2.equals("null")){
aperturePhotoArray[2]=aperturePhoto2;
}
}
shutterPhoto =intent.getString("shutterPhoto");
shutterPhoto1 =intent.getString("shutterPhoto1");
shutterPhoto2 =intent.getString("shutterPhoto2");
shutterPhotoArray[0]= shutterPhoto;
if(!shutterPhoto1.equals("null")){
shutterPhotoArray[1]=shutterPhoto1;
if(!shutterPhoto2.equals("null")){
shutterPhotoArray[2]=shutterPhoto2;
}
}
isoPhoto =intent.getString("isoPhoto");
isoPhoto1 =intent.getString("isoPhoto1");
isoPhoto2 =intent.getString("isoPhoto2");
isoPhotoArray[0]= isoPhoto;
if(!isoPhoto1.equals("null")){
isoPhotoArray[1]=isoPhoto1;
if(!isoPhoto2.equals("null")){
isoPhotoArray[2]=isoPhoto2;
}
}
focal_lengthPhoto=intent.getString("focal_lengthPhoto");
focal_lengthPhoto1=intent.getString("focal_lengthPhoto1");
focal_lengthPhoto2=intent.getString("focal_lengthPhoto2");
focal_lengthPhotoArray[0]= focal_lengthPhoto;
if(!focal_lengthPhoto1.equals("null")){
focal_lengthPhotoArray[1]=focal_lengthPhoto1;
if(!focal_lengthPhoto2.equals("null")){
focal_lengthPhotoArray[2]=focal_lengthPhoto2;
}
}
TextView txtaperture_suggested = (TextView) findViewById(R.id.aperture_suggested);
TextView txtfilter_suggested = (TextView) findViewById(R.id.filter_suggested);
TextView txtiso_suggested = (TextView) findViewById(R.id.iso_suggested);
TextView txtlens_suggested = (TextView) findViewById(R.id.lens_suggested);
TextView txtshutter_suggested = (TextView) findViewById(R.id.shutter_suggested);
TextView txtshot_levelsuggested = (TextView) findViewById(R.id.shot_levelsuggested);
if (suggested_shot_level == "1") {
txtshot_levelsuggested.setText("Easy");
} else if (suggested_shot_level =="2") {
txtshot_levelsuggested.setText("Medium");
} else if (suggested_shot_level =="3") {
txtshot_levelsuggested.setText("Difficult");
} else if (suggested_shot_level =="4"){
txtshot_levelsuggested.setText("Pro");
}
txtaperture_suggested.setText(suggested_aperture);
txtfilter_suggested.setText(suggested_filter);
txtiso_suggested.setText(suggested_iso);
txtshutter_suggested.setText(suggested_shutter);
txtlens_suggested.setText(suggested_lens);
/* TextView txtshutterPhoto = (TextView) findViewById(R.id.shutterPhoto);
TextView txtshutterPhoto2 = (TextView) findViewById(R.id.shutterPhoto2);
TextView txtshutterPhoto3 = (TextView) findViewById(R.id.shutterPhoto3);
TextView txtshot_levelPhoto = (TextView) findViewById(R.id.shot_levelPhoto);
TextView txtshot_levelPhoto2 = (TextView) findViewById(R.id.shot_levelPhoto2);
TextView txtshot_levelPhoto3 = (TextView) findViewById(R.id.shot_levelPhoto3);
TextView txtaperturePhoto = (TextView) findViewById(R.id.aperturePhoto);
TextView txtaperturePhoto2 = (TextView) findViewById(R.id.aperturePhoto2);
TextView txtaperturePhoto3 = (TextView) findViewById(R.id.aperturePhoto3);
TextView txtfilterPhoto = (TextView) findViewById(R.id.filterPhoto);
TextView txtfilterPhoto2 = (TextView) findViewById(R.id.filterPhoto2);
TextView txtfilterPhoto3 = (TextView) findViewById(R.id.filterPhoto3);
TextView txtisoPhoto = (TextView) findViewById(R.id.isoPhoto);
TextView txtisoPhoto2 = (TextView) findViewById(R.id.isoPhoto2);
TextView txtisoPhoto3 = (TextView) findViewById(R.id.isoPhoto3);
TextView txtfocal_lengthPhoto = (TextView) findViewById(R.id.lensPhoto);
TextView txtfocal_lengthPhoto2 = (TextView) findViewById(R.id.lensPhoto2);
TextView txtfocal_lengthPhoto3 = (TextView) findViewById(R.id.lensPhoto3);*/
/* if (shot_levelPhotoArray[0] == "1") {
txtshot_levelPhoto.setText("Easy");
shot_levelPhotoArray[0] = "Easy";
*//*txtshot_levelPhoto2.setText("Easy");
txtshot_levelPhoto3.setText("Easy");*//*
} else if (shot_levelPhotoArray[0] == "2") {
txtshot_levelPhoto.setText("Medium");
shot_levelPhotoArray[0] = "Medium";
*//* txtshot_levelPhoto2.setText("Medium");
txtshot_levelPhoto3.setText("Medium");*//*
} else if (shot_levelPhotoArray[0] == "3") {
txtshot_levelPhoto.setText("Difficult");
shot_levelPhotoArray[0] = "Difficult";
*//*txtshot_levelPhoto2.setText("Difficult");
txtshot_levelPhoto3.setText("Difficult");*//*
} else {
txtshot_levelPhoto.setText("Pro");
shot_levelPhotoArray[0] = "Pro";
*//* txtshot_levelPhoto2.setText("Pro");
txtshot_levelPhoto3.setText("Pro");*//*
}
txtshutterPhoto.setText(shutterPhoto);
txtisoPhoto.setText(isoPhoto);
txtfilterPhoto.setText(filterPhoto);
txtaperturePhoto.setText(aperturePhoto);
txtfocal_lengthPhoto.setText(focal_lengthPhoto);*/
/*txtshutterPhoto.setText(shutterPhoto[0]);
if (shutterPhoto.length > 1) {
txtshutterPhoto2.setText(shutterPhoto[1]);
if (shutterPhoto.length > 2) {
txtshutterPhoto3.setText(shutterPhoto[2]);
}
}
txtisoPhoto.setText(isoPhoto[0]);
if (isoPhoto.length > 1) {
txtisoPhoto2.setText(isoPhoto[1]);
if (isoPhoto.length > 2) {
txtisoPhoto3.setText(isoPhoto[2]);
}
}
txtfilterPhoto.setText(filterPhoto[0]);
if (filterPhoto.length > 1) {
txtfilterPhoto2.setText(filterPhoto[1]);
if ((filterPhoto.length > 2)) {
txtfilterPhoto3.setText(filterPhoto[2]);
}
}
txtaperturePhoto.setText(aperturePhoto[0]);
if (aperturePhoto.length > 1) {
txtaperturePhoto2.setText(aperturePhoto[1]);
if (aperturePhoto.length > 2) {
txtaperturePhoto3.setText(aperturePhoto[2]);
}
}*/
try {
fis = getApplicationContext().openFileInput("bmImg1");
bmImg1 = BitmapFactory.decodeStream(fis);
IMAGES.add(bmImg1);
DESCRIPTIONS.add(descriptionPhoto[0]);
SHOTLEVEL.add(shot_levelPhotoArray[0]);
FILTERPHOTO.add(filterPhotoArray[0]);
APERTUREPHOTO.add(aperturePhotoArray[0]);
SHUTTERPHOTO.add(shutterPhotoArray[0]);
ISOPHOTO.add(isoPhotoArray[0]);
LENSPHOTO.add(focal_lengthPhotoArray[0]);
fis.close();
if(numpics>1){
fis2 = getApplicationContext().openFileInput("bmImg2");
bmImg2 = BitmapFactory.decodeStream(fis2);
IMAGES.add(bmImg2);
DESCRIPTIONS.add(descriptionPhoto[1]);
SHOTLEVEL.add(shot_levelPhotoArray[1]);
FILTERPHOTO.add(filterPhotoArray[1]);
APERTUREPHOTO.add(aperturePhotoArray[1]);
SHUTTERPHOTO.add(shutterPhotoArray[1]);
ISOPHOTO.add(isoPhotoArray[1]);
LENSPHOTO.add(focal_lengthPhotoArray[1]);
fis2.close();
if(numpics>2){
fis3 = getApplicationContext().openFileInput("bmImg3");
bmImg3 = BitmapFactory.decodeStream(fis3);
IMAGES.add(bmImg3);
DESCRIPTIONS.add(descriptionPhoto[2]);
SHOTLEVEL.add(shot_levelPhotoArray[2]);
FILTERPHOTO.add(filterPhotoArray[2]);
APERTUREPHOTO.add(aperturePhotoArray[2]);
SHUTTERPHOTO.add(shutterPhotoArray[2]);
ISOPHOTO.add(isoPhotoArray[2]);
LENSPHOTO.add(focal_lengthPhotoArray[2]);
fis3.close();
}
}
}
catch (FileNotFoundException e) {
Log.d(TAG, "file not found");
e.printStackTrace();
}
catch (IOException e) {
Log.d(TAG, "io exception");
e.printStackTrace();
}
PagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), descriptionPhoto[position_pic]);
page = (ViewPager)findViewById(R.id.pager);
page.setAdapter(pagerAdapter);
page.setCurrentItem(position_pic);
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
public void clear() {
IMAGES.clear();
DESCRIPTIONS.clear();
SHOTLEVEL.clear();
FILTERPHOTO.clear();
APERTUREPHOTO.clear();
SHUTTERPHOTO.clear();
ISOPHOTO.clear();
LENSPHOTO.clear();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
String description;
public ScreenSlidePagerAdapter(FragmentManager fm, String description) {
super(fm);
this.description=description;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
}
//this is called when notifyDataSetChanged() is called
@Override
public int getItemPosition(Object object) {
// refresh all fragments when data set changed
return PagerAdapter.POSITION_NONE;
}
@Override
public boolean isViewFromObject(View view, Object object) {
if(object != null){
return ((Fragment)object).getView() == view;
}else{
return false;
}
}
/*@Override
public Fragment getItem(int position) {
ViewPagerFragment fragment = new ViewPagerFragment();
fragment.setAsset(IMAGES.get(position));
return fragment;
}*/
@Override
public Fragment getItem(int index) {
ViewPagerFragment fragment = new ViewPagerFragment();
//fragment.setAsset(IMAGES.get(index));
fragment.setAsset(IMAGES.get(index), DESCRIPTIONS.get(index));
ViewPagerFragment.newInstance(index,
SHOTLEVEL.get(index),
FILTERPHOTO.get(index),
APERTUREPHOTO.get(index),
SHUTTERPHOTO.get(index),
ISOPHOTO.get(index),
LENSPHOTO.get(index)); // Pages is an array of Strings
return fragment;
}
@Override
public int getCount() {
return IMAGES.size();
}
}
}
This is the Fragment
public class ViewPagerFragment extends Fragment {
private static final String BUNDLE_ASSET = "res";
private Bitmap asset;
String descriptionPhoto;
private TextView tv;
HashMap<Bitmap, String > map;
private static Bundle bundle;
public ViewPagerFragment() {
}
/*public int setAsset(Bitmap asset) {
this.asset = asset;
return 0;
}*/
public HashMap<Bitmap, String> setAsset(Bitmap asset, String description){
map= new HashMap<>();
this.asset = asset;
this.descriptionPhoto=description;
map.put(this.asset, this.descriptionPhoto);
return map;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.view_pager_page, container, false);
if (savedInstanceState != null) {
if (asset == null && savedInstanceState.containsKey(BUNDLE_ASSET)) {
asset = savedInstanceState.getParcelable(BUNDLE_ASSET);
}
}
if (asset != null && descriptionPhoto!=null) {
TextView descriptionnote = (TextView) rootView.findViewById(R.id.note1);
if(descriptionPhoto.equals("null")){
descriptionPhoto="No description for this picture";
}
descriptionnote.setText(descriptionPhoto);
SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)rootView.findViewById(R.id.imageView);
imageView.setImage(ImageSource.bitmap(asset));
TextView txtshot_level = (TextView) rootView.findViewById(R.id.shot_levelPhoto);
TextView txtshutterPhoto = (TextView) rootView.findViewById(R.id.shutterPhoto);
TextView txtaperturePhoto = (TextView) rootView.findViewById(R.id.aperturePhoto);
TextView txtfilterPhoto = (TextView) rootView.findViewById(R.id.filterPhoto);
TextView txtisoPhoto = (TextView) rootView.findViewById(R.id.isoPhoto);
TextView txtfocal_lengthPhoto = (TextView) rootView.findViewById(R.id.lensPhoto);
txtshot_level.setText(bundle.getString("shot_levelcontent"));
txtshutterPhoto.setText(bundle.getString("shuttercontent"));
txtisoPhoto.setText(bundle.getString("isocontent"));
txtfilterPhoto.setText(bundle.getString("filtercontent"));
txtaperturePhoto.setText(bundle.getString("aperturecontent"));
txtfocal_lengthPhoto.setText(bundle.getString("lenscontent"));
}
return rootView;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
View rootView = getView();
if (rootView != null) {
outState.putString(BUNDLE_ASSET, String.valueOf(asset));
}
}
public static Fragment newInstance(int position,
String shot_level,
String filter,
String aperture,
String shutter,
String iso,
String lens) {
ViewPagerFragment swipeFragment = new ViewPagerFragment();
bundle = new Bundle();
if (shot_level.equals("1")) {
bundle.putString("shot_levelcontent", "Easy");
} else if (shot_level.equals("2")) {
bundle.putString("shot_levelcontent", "Medium");
} else if (shot_level.equals("3")) {
bundle.putString("shot_levelcontent", "Difficult");
} else {
bundle.putString("shot_levelcontent", "Pro");
}
bundle.putString("filtercontent", filter);
bundle.putString("aperturecontent", aperture);
bundle.putString("shuttercontent", shutter);
bundle.putString("isocontent", iso);
bundle.putString("lenscontent", lens);
swipeFragment.setArguments(bundle);
return swipeFragment;
}
}
这篇关于ViewPager活动内容的变化时,幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!