Json 如何使用毕加索添加图像

Json 如何使用毕加索添加图像,json,picasso,java,android,android-image,Json,Picasso,Java,Android,Android Image,我正在尝试将图像添加到我的listview,它是由从中检索的内容生成的。为了添加我正在尝试使用的图像,我已经看了一个关于它的文章,它很有效,问题是我认为它不能在我的应用程序中使用,至少不能用我看到的方法。 这是我的代码,希望任何人都能帮助我,并解释如何做到这一点 public class TodosOsPaises extends AppCompatActivity { private String TAG = TodosOsPaises.class.getSimpleName();

我正在尝试将图像添加到我的listview,它是由从中检索的内容生成的。为了添加我正在尝试使用的图像,我已经看了一个关于它的文章,它很有效,问题是我认为它不能在我的应用程序中使用,至少不能用我看到的方法。 这是我的代码,希望任何人都能帮助我,并解释如何做到这一点

public class TodosOsPaises extends AppCompatActivity {

    private String TAG = TodosOsPaises.class.getSimpleName();
    private ProgressDialog pDialog;
    private ListView lv;
    private static String url = "http://";
    ArrayList<HashMap<String, String>> listaPaises;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_todos_os_paises);

        listaPaises = new ArrayList<>();
        lv = (ListView) findViewById(R.id.list);
        new GetPaises().execute();
    }

    private class GetPaises extends AsyncTask<Void, Void, Void> implements Serializable {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(TodosOsPaises.this);
            pDialog.setMessage("Aguarde...");
            pDialog.setCancelable(false);
            pDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            HttpHandler sh = new HttpHandler();
            final String jsonStr = sh.makeServiceCall(url);
            Log.e(TAG, "Response from URL: " + jsonStr);
            if (jsonStr != null) {
                try {
                    JSONArray array = new JSONArray(jsonStr);
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject jsonObject = array.getJSONObject(i);
                        JSONArray paises = jsonObject.optJSONArray("paises");
                        if (paises != null) {
                            for (int j = 0; j < paises.length(); j++) {
                                JSONObject jsonObject1 = paises.getJSONObject(j);

                                String K_PAIS = jsonObject1.getString("K_PAIS");
                                String Designacao = jsonObject1.getString("Designacao");
                                String URL_IMAGE_SMALL = jsonObject1.getString("URL_IMAGE_SMALL");
                                String Coord_LAT = jsonObject1.getString("Coord_LAT");
                                String Coord_LONG = jsonObject1.getString("Coord_LONG");
                                String Coord_Zoom = jsonObject1.getString("Coord_Zoom");

                                HashMap<String, String> pais = new HashMap<>();


                                pais.put("K_PAIS", K_PAIS);
                                pais.put("Designacao", Designacao);
                                pais.put("URL_IMAGE_SMALL", URL_IMAGE_SMALL);
                                pais.put("URL_IMAGEM", URL_IMAGEM);
                                pais.put("Coord_LAT", Coord_LAT);
                                pais.put("Coord_LONG", Coord_LONG);
                                pais.put("Coord_Zoom", Coord_Zoom);

                                listaPaises.add(pais);
                            }
                        }
                    }
                } catch (final JSONException e) {
                    Log.e(TAG, "Json parsing error: " + e.getMessage());
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(), "Json parsin error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                        }
                    });
                }

            } else {
                Log.e(TAG, "Couldn't get json from server.");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Couldn't get json from server. Check LogCat for possible errpr!", Toast.LENGTH_LONG).show();
                    }
                });
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            if (pDialog.isShowing()) {
                pDialog.dismiss();
            }
            ListAdapter adapter = new SimpleAdapter(TodosOsPaises.this, listaPaises, R.layout.list_item, new String[]{"Designacao", "URL_IMAGEM"},
                    new int[]{R.id.Designacao, R.id.imageViewPais});
            lv.setAdapter(adapter);
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> pare, View view, int position, long id) {
                    Intent intent = new Intent(TodosOsPaises.this, MapsActivity.class);
                    intent.putExtra("data", listaPaises.get(position));
                    startActivity(intent);
                }
            });

            Collections.sort(listaPaises, new Comparator<HashMap<String, String>>() {
                @Override
                public int compare(HashMap<String, String> first, HashMap<String, String> second) {
                    String firstValue = first.get("Designacao");
                    String secondValue = second.get("Designacao");
                    return firstValue.compareTo(secondValue);
                }
            });
        }
    }  
}
public类todosospaies扩展了AppCompative活动{
private String TAG=TodosOsPaises.class.getSimpleName();
私人对话;
私有ListView lv;
私有静态字符串url=“http://”;
ArrayList列表;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u todos\u os\u paises);
listaPaises=新的ArrayList();
lv=(ListView)findViewById(R.id.list);
新建GetPaises().execute();
}
私有类GetPaises扩展AsyncTask实现可序列化{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=newprogressdialog(TodosOsPaises.this);
pDialog.setMessage(“Aguarde…”);
pDialog.setCancelable(假);
pDialog.show();
}
@凌驾
受保护的Void doInBackground(Void…参数){
HttpHandler sh=新的HttpHandler();
最终字符串jsonStr=sh.makeServiceCall(url);
Log.e(标签,“来自URL的响应:+jsonStr”);
if(jsonStr!=null){
试一试{
JSONArray数组=新的JSONArray(jsonStr);
对于(int i=0;i
但是,我的问题是“内容”如何?我的应用程序中没有内容,创建变量“Context content=null;”就足够了吗?@alb请尝试用户“this”或“getContent()”或“getActivity()”我无法给出一个答案。AppCompactActivity扩展内容(请阅读一些关于android应用程序结构的文章)@alb Try use Context=TodosOsPaises.this;
Picasso.with(content)
            .load("path_or_url_or_file")
            .into(new Target() {
                @Override public void onBitmapLoaded(final Bitmap bitmap,
                        final Picasso.LoadedFrom from) {

                }

                @Override public void onBitmapFailed(final Drawable errorDrawable) {

                }

                @Override public void onPrepareLoad(final Drawable placeHolderDrawable) {

                }
            });