如何通过获取共享首选项返回的值来设置imageview

时间:2015-04-14 07:36:43

标签: android json

嗨朋友,我在主要活动中从json获取图像,并使用共享首选项将其发送到我的第二个活动。但我无法在我从json检索到的imageview中显示图像

我的主要活动代码,我从json获取图像并使用共享首选项发送到下一个活动。

listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
                    long id) { 
String purtimage = ((ImageView) view.findViewById(R.id.largimage)).getContext().toString();
// Starting new intent

                Intent intent = new Intent(getApplicationContext(),CarDetails.class);
                Editor editor = prefs.edit();
                //intent.putExtra("image", largimage);
                editor.commit();
                startActivity(intent);
            }   
        });

这是我的第二个活动,我试图在图像视图中显示图像。

prefs = getSharedPreferences("Share",
                    getApplicationContext().MODE_PRIVATE);

         String largimage = prefs.getString("image", "");
         ImageView limage = (ImageView) findViewById(R.id.imageView1);
         limage.setContentDescription(largimage);

请帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

使用Picasso。使用编译compile 'com.squareup.picasso:picasso:2.5.2'在android studio中包含它  或者包含来自HERE的jar文件。

然后只需使用此行

Picasso.with(context).load("largimage").into(limage);