我正在使用此库(https://github.com/darsh2/MultipleImageSelect)从图库中选择图像并将图像设置为Imageviews。在onActivityResult()中,我使用ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
来获取所选图像的路径。但是我无法将我选择的图像设置为ImageViews。
代码:
Intent intent = new Intent(AddOffers.this, AlbumSelectActivity.class);
//set limit on number of images that can be selected, default is 10
intent.putExtra(Constants.INTENT_EXTRA_LIMIT, 3);
startActivityForResult(intent, Constants.REQUEST_CODE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null) {
//The array list has the image paths of the selected images
ArrayList<Image> images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
offr_img1.setImageUri(images.get(0));
}}
答案 0 :(得分:1)
我看到的是您传递完整的Image对象,但是您需要传递路径来设置图像。
在您的代码中,尝试更改此内容 -
offr_img1.setImageUri(images.get(0));
到
offr_img1.setImageUri(images.get(0).path);
答案 1 :(得分:1)
使用此:
theory Scratch
imports Main
begin
ML {*
(* In reality, this would of course be a much more complex parser. *)
val my_parser : term parser = Parse.nat >> HOLogic.mk_nat
(* This function should invoke my_parser to parse the content of cartouche.
Parse errors should be properly reported (i.e., with red highlighting in
jEdit etc. *)
fun parse_cartouche ctx (cartouche:string) (pos:Position.T) : term =
(warning ("I should parse: " ^ cartouche ^ ". Returning arbitrary term instead"); @{term True})
(* Modified from Cartouche_Examples.thy *)
fun cartouche_tr (ctx:Proof.context) args =
let fun err () = raise TERM ("cartouche_tr", args) in
(case args of
[(c as Const (@{syntax_const "_constrain"}, _)) $ Free (s, _) $ p] =>
(case Term_Position.decode_position p of
SOME (pos, _) => c $ (parse_cartouche ctx s pos) $ p
| NONE => err ())
| _ => err ())
end;
*}
syntax "_my_syntax" :: "cartouche_position ⇒ 'a" ("MY_")
parse_translation ‹[(@{syntax_const "_my_syntax"}, cartouche_tr)]›
term "(MY ‹123›, 3)" (* Should parse as (123,3) *)
end