I have to read the image from my website. However, the images uploaded by users in the server have variety extensions. jpg png etc. How I can modify the image_url
code to detect the extension of the image automatically without having to declare it as static
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);
This is because the name of the image file is not fixed. So how can I display it properly the image with its correct extension.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…