我对如何解决这个问题有一个想法,但是需要一些编码方面的专业知识。
我目前设置了一个图像选择器,用户可以在其中选择多个皮克特。我也有一个使用pageViewer的滑块开发人员。现在,pageViewer的问题在于,它要求在运行应用程序之前已经存储了图像,以便它可以在滑块中显示这些图像。
这就是我的想法,我希望可以做到。
imageSelected_1
','imageSelected_2
','imageSelect_3
'等。这就是我们将这些成像仪关联的方式这就是我想到的选择图像并将其显示在滑块中的方式。我需要的帮助是实施。
以下是用于选择多张图像的代码:
PhotosActivity:
public void openGallery() {
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), PICK_IMAGE_MULTIPLE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
try {
// When an Image is picked
if (requestCode == 1 && resultCode == RESULT_OK
&& null != data) {
// Get the Image from data
String[] filePathColumn = { MediaStore.Images.Media.DATA };
imagesEncodedList = new ArrayList<String>();
if(data.getData()!=null){
Uri mImageUri=data.getData();
// Get the cursor
Cursor cursor = getContentResolver().query(mImageUri,
filePathColumn, null, null, null);
// Move to first row
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imageEncoded = cursor.getString(columnIndex);
cursor.close();
imageDisplay.setImageURI(mImageUri);
}
} else {
Toast.makeText(this, "You haven't picked Image",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
.show();
}
super.onActivityResult(requestCode, resultCode, data);
}
下面是viewPagerAdapter,并从PhotoActivites对其进行调用以调用imageslider。它现在从drawable文件夹中拍照,但希望它与我以前的项目符号要匹配。
photosViewPagerAdapter:
public class PhotosViewPagerAdapter extends PagerAdapter {
private Context context;
private LayoutInflater layoutInflater;
private Integer [] images = {R.drawable.question, R.drawable.love_heart, R.drawable.love_heart_dark};
public PhotosViewPagerAdapter(Context context){
this.context = context;
}
@Override
public int getCount() {
return images.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position){
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.activity_photos, null);
ImageView imageView = view.findViewById(R.id.image_content);
imageView.setImageResource(images[position]);
ViewPager vp = (ViewPager) container;
vp.addView(view, 0);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object){
ViewPager vp = (ViewPager) container;
View view = (View) object;
vp.removeView(view);
}
PhotosActivity:
ViewPager photosSlider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PhotosViewPagerAdapter photosViewPagerAdapter = new PhotosViewPagerAdapter(PhotosActivity.this);
photosSlider.setAdapter(photosViewPagerAdapter);