我有一个项目,需要上传一些图像。我已经成功完成了,但是用户必须单击6个按钮才能在屏幕上获取6张图像。效率不是很高,所以我四处询问,并被告知要使用imagepicker。
我已经实现了此https://github.com/siralam/BSImagePicker,它使一切变得容易,但是我真的在(不知道)如何使那些图像上载到存储并将路径存储在数据库中。
我知道的方法是在onActivityResult上获取mimage1Uri = data.getData();
。
有人可以帮我得到尿液吗?
很抱歉,如果您发现这个问题太麻烦了。
public class PostFragment extends Fragment implements BSImagePicker.OnMultiImageSelectedListener {
private ImageView ivImage1, ivImage2, ivImage3, ivImage4, ivImage5, ivImage6;
private EditText mTitle, mDescription, mPrice, mCountry, mStateProvince, mCity, mContactEmail;
private Button mPost;
private ProgressBar mProgressBar;
private double mProgress = 0;
private Uri mSelectedUri;
private Uri mSelectedUri1;
private byte[] mUploadBytes;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_post, container, false);
ivImage1 = view.findViewById(R.id.iv_image1);
ivImage2 = view.findViewById(R.id.iv_image2);
ivImage3 = view.findViewById(R.id.iv_image3);
ivImage4 = view.findViewById(R.id.iv_image4);
ivImage5 = view.findViewById(R.id.iv_image5);
ivImage6 = view.findViewById(R.id.iv_image6);
mTitle = view.findViewById(R.id.input_title);
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
view.findViewById(R.id.tv_multi_selection).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BSImagePicker pickerDialog = new BSImagePicker.Builder("")
.setMaximumDisplayingImages(Integer.MAX_VALUE)
.isMultiSelect()
.setMinimumMultiSelectCount(3)
.setMaximumMultiSelectCount(6)
.build();
pickerDialog.show(getChildFragmentManager(), "picker");
}
});
startPosting();
return view;
}
public void onMultiImageSelected(List<Uri> uriList, String tag) {
for (int i = 0; i < uriList.size(); i++) {
if (i >= 6) return;
ImageView iv;
switch (i) {
case 0:
iv = ivImage1;
break;
case 1:
iv = ivImage2;
break;
case 2:
iv = ivImage3;
break;
case 3:
iv = ivImage4;
break;
case 4:
iv = ivImage5;
break;
case 5:
default:
iv = ivImage6;
}
Glide.with(this).load(uriList.get(i)).into(iv);
答案 0 :(得分:1)
听起来很简单...
public int setPrice(String price_id, String type){
.........................
return price;
}
int price1 = setPrice(3,'econ');
int price2 = setPrice(4,'platinum');