1

我使用 JSON 从网络上传图片并将它们放在画廊视图中。但问题是我希望当我点击其中一张图片时,它会在其他活动上显示主题或者不知道是什么,只显示我点击的图片,这是显示画廊的 Java 代码:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    cacheDir = StorageUtils.getOwnCacheDirectory(this, "WydadNewsImageLoader/Cache");
    imageLoader = ImageLoader.getInstance();
    config = new ImageLoaderConfiguration.Builder(this)
    .memoryCacheExtraOptions(480, 800)
    .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75) 
    .threadPoolSize(3)
    .threadPriority(Thread.NORM_PRIORITY - 1)
    .denyCacheImageMultipleSizesInMemory()
    .offOutOfMemoryHandling()
    .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
    .discCache(new UnlimitedDiscCache(cacheDir))
    .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
    .imageDownloader(new URLConnectionImageDownloader(5 * 1000, 20 * 1000))
    .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
    .build();
    imageLoader.init(config);
    options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.photo_porfile_commentaire)
    .showImageForEmptyUri(R.drawable.photo_porfile_commentaire).cacheInMemory()
    .cacheOnDisc().imageScaleType(ImageScaleType.POWER_OF_2)
    .build();
    galleryView = (Gallery)findViewById(R.id.gallery1);
    //galleryView.setAdapter();   
    init();
}

public void init(){


    new FetchPlayers().execute();
}

class ImageAdapter extends ArrayAdapter<Players> {

    public ImageAdapter(Context context, int textViewResourceId, List<Players> objects) {
        super(context, textViewResourceId, objects);
    }

    public View getView(int position, View convertView, ViewGroup parent) {   
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View vi=convertView;   
        Players players = getItem(position);
        if(convertView==null){  

            vi = inflater.inflate(R.layout.pictures, null); 

            ImageView image=(ImageView) vi.findViewById(R.id.imageView1);
            TextView text1=(TextView)vi.findViewById(R.id.textView1);  
            TextView text2=(TextView)vi.findViewById(R.id.textNom);
            TextView text3=(TextView)vi.findViewById(R.id.textPost);
            TextView text4=(TextView)vi.findViewById(R.id.textDdn);

            text1.setText(players.getNm()); 
            text2.setText(Html.fromHtml( players.getNom()).toString());
            text3.setText(Html.fromHtml( players.getPost()).toString());
            text4.setText(players.getDdn());

            imageLoader.displayImage(players.getImage(), image, options);


        }
        return vi;        
    }
        public void onClick(View arg0) {
        players = Services.getPlayers(Gallery_Activity.this);
        Intent newintent = new Intent(Gallery_Activity.this, Gallery_Player.class);
        newintent.putExtra("image", R.imgviews.imgplayer);
        startActivity(newintent);
    }
}


class FetchPlayers extends AsyncTask<Void, Void, Void> {

    private ProgressDialog progressDialog;
    @Override
    protected void onPreExecute() {         
        super.onPreExecute();
        progressDialog = ProgressDialog.show(Gallery_Activity.this, "", getString(R.string.loading_message));
    }
    @Override
    protected Void doInBackground(Void... params) {
        players = Services.getPlayers(Gallery_Activity.this);

        return null;
    }
    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        progressDialog.dismiss();
        progressDialog.setCancelable(true);
    }
}

我应该在其他活动中做什么或我应该做什么?

4

1 回答 1

0

在 baseAdapter 类的 getView() 的 imageview 中添加 Click 事件

image.setOnclickListerner(//做某事)

setOnclickListerner中,您可以做两件事,

首先,您可以通过 android intent 发送图像 url 并将其保存在另一个活动中,然后显示来自该 url 的图像

Intent search = new Intent(content, SecondActivity.class);
bundle.putString("param_a","Image_url");
search.putExtras(bundle);
context.startActivity(search);

或者

您可以将图像转换为 base64字符串并通过 android Intent 传递,就像上一个一样。

Bitmap bitmap=convert Imageview to bitamp;
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image=stream.toByteArray();

String img_str = Base64.encodeToString(image, 0);

并再次将base64字符串返回到图像并在另一个活动中显示它的imageview。

于 2013-05-23T09:26:09.833 回答