【发布时间】:2014-06-02 05:20:42
【问题描述】:
我必须从我的网站上读取图像。但是,用户在服务器上传的图片有多种扩展名。 jpg png 等。如何修改image_url 代码以自动检测图像的扩展名,而无需将其声明为静态
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_product, container, false);
// Loader image - will be shown before loading image
int loader = R.drawable.loader;
editTxtQuantity = (EditText)rootView.findViewById(R.id.inputQuantity);
btnAddtocart = (Button) rootView.findViewById(R.id.btnAddtocart);
btnCancel = (Button) rootView.findViewById(R.id.btnCancel);
productErrorMsg = (TextView) rootView.findViewById(R.id.product_error);
txtName = (TextView) rootView.findViewById(R.id.inputName);
txtPrice = (TextView) rootView.findViewById(R.id.inputPrice);
txtDesc = (TextView) rootView.findViewById(R.id.inputDesc);
// Imageview to show
image = (ImageView) rootView.findViewById(R.id.image);
// Getting productid from ScanFragment
pid = getArguments().getString("pid");
// Image url
String image_url = "http://smartqr.droid-addict.com/upload/products/" + pid +".png";
// ImageLoader class instance
ImageLoader imgLoader = new ImageLoader(getActivity().getApplicationContext());
// whenever you want to load an image from url
// call DisplayImage function
// url - image url to load
// loader - loader image, will be displayed before getting image
// image - ImageView
imgLoader.DisplayImage(image_url, loader, image);
这是因为图像文件的名称不固定。那么如何正确显示具有正确扩展名的图像。
【问题讨论】:
-
你有图片的全名吗?文件名+扩展名?
-
从“testing-123.com/upload/products”获取所有文件名,然后用
startsWith(pid)检查它是否是你的文件然后下载。 -
@shayanpourvatan 是的,现在我是 pid+png。我必须将所有图像转换为png。举些例子。 pid = 0001 因此 0001.png。现在我希望它自动显示图像,不管它的扩展名。
标签: java android android-fragments imageview