如何从公共/私有类访问HashMap数据

时间:2014-03-04 19:42:02

标签: java android hashmap

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

我的活动中的onclick听众:

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);
            }
        });

MY confirmEvent:

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");
    }

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

我的HashMap(相关代码):

/** 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”?

1 个答案:

答案 0 :(得分:0)

该修复程序将此添加到我的onClickListener

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

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

您还可以举报imgURI字符串以验证Map包含的内容。