我有一個觀點尋呼機和三個選項卡像 「FragmentOne」「FragmentTwo」等片段標籤viewpager問題
在每個片段(頁)的片段我想設置從畫廊或從camera.But圖像當我在FragmentOne選項卡中設置圖像(位圖)時,位圖也顯示在其他片段中。但我想要獨特的選擇圖像應顯示在各自片段的ImageView中。
My ViewPager類看起來像。
public class MainFragment extends Fragment {
private ViewPager mViewPager;
private SlidingTabLayout mSlidingTabLayout;
// Tabs titles
private String[] tabsTitles = {"One", "Two", "Three"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.new_proj_frag_layout, container, false);
// ViewPager
mViewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
mViewPager.setOffscreenPageLimit(3);
mViewPager.setAdapter(new ViewPagerAdapter(getChildFragmentManager(), tabsTitles));
// Sliding tab layout
mSlidingTabLayout = (SlidingTabLayout) rootView.findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setViewPager(mViewPager);
return rootView;
}
FragmentOne
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.white_fragment_layout, container, false);
image_one_btn = (ImageView) rootView.findViewById(R.id.image_one_click);
image_one_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectImage();
}
});
return rootView;
}
private void selectImage() {
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
getParentFragment().startActivityForResult(i, 1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getActivity().getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
Log.i("ImagePath:","===="+picturePath);
image_one_btn.setImageBitmap(BitmapFactory.decodeFile(picturePath));
cursor.close();
} else {
Toast.makeText(getActivity(), "Try Again!!", Toast.LENGTH_SHORT).show();
}
}
ViewPagerAdapter
public class ViewPagerAdapter extends FragmentPagerAdapter {
private String[] tabsTitles;
public ViewPagerAdapter(FragmentManager fm, String[] tabsTitles) {
super(fm);
this.tabsTitles = tabsTitles;
}
@Override
public CharSequence getPageTitle(int position) {
return tabsTitles[position];
}
@Override
public Fragment getItem(int index) {
switch(index) {
case 0:
return new ImageOneFragment();
case 1:
return new ImageTwoFragment();
case 2:
return new ImageThreeFragment();
}
return null;
}
@Override
public int getCount() {
return tabsTitles.length;
}
}
片段二代碼在哪裏?請你把它放在這裏。 – Pinakin 2015-02-09 11:53:42
FragmentTwo代碼也類似於fragmentOne代碼。 – 2015-02-09 11:57:03
可以請你發佈你的視圖尋呼機適配器實現嗎? – Pinakin 2015-02-09 11:58:11