如何从公共/私有类访问哈希图数据



我正在通过参数将图像从活动传递到对话框IMageview。但是,当图像出现在对话框的图像视图中时,它是模糊的并且质量非常差。请参阅下面的代码:

我的活动中的点击监听器:

mListView.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                //String item = ((TextView)view).getText().toString();
                //int img = ((ImageView)view.findViewById(R.id.event_pic)).getId();
                ImageView img = ((ImageView)view.findViewById(R.id.event_pic));
                img.buildDrawingCache();
                Bitmap bitmap = img.getDrawingCache();
                String txt =((TextView)view.findViewById(R.id.subTitle_single)).getText().toString();
                //Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
                confirmEvent(txt, bitmap);
            }
        });

我的确认事件 :

public void confirmEvent(CharSequence text, Bitmap id) {
        DialogFragment mDialog = new MyDialogFragment();
        Bundle args = new Bundle();
        args.putCharSequence("text", text);
        args.putParcelable("id", id);
        mDialog.setArguments(args);
        mDialog.show(getSupportFragmentManager(), "missiles");
    }

我怀疑这是因为当它到达图像视图时,它已经被压缩并格式化为该图像视图。我知道我应该从图像视图中获取图像路径而不是图像,但我不确定语法是否正确。由于图像是从网站解析的 JSON 并存储在 harshMap 中:

我的哈希图(相关代码):

/** AsyncTask to download and load an image in ListView */
private class ImageLoaderTask extends AsyncTask<HashMap<String, Object>, Void, HashMap<String, Object>>{
    @Override
    protected HashMap<String, Object> doInBackground(HashMap<String, Object>... hm) {
....
// Create a hashmap object to store image path and its position in the listview
            HashMap<String, Object> hmBitmap = new HashMap<String, Object>();
            // Storing the path to the temporary image file
            hmBitmap.put("event_img",tmpFile.getPath());
            // Storing the position of the image in the listview
            hmBitmap.put("position",position);              
            // Returning the HashMap object containing the image path and position
            return hmBitmap;

访问此 hmBitmap 对象的正确语法是什么,以便我可以使用"event_img"?

修复是将其添加到我的onClickListener

HashMap<String, Object> currentimg = (HashMap<String, Object>) adapter.getItem(position);
                String imgURI = currentimg.get("event_img").toString();

显然,我的HashMap已经公开了,通过一些阅读和研究,我学会了如何实施HashMap

还可以对imgURI字符串进行烘烤,以验证Map包含的内容。

最新更新