在Listview中获取图像

时间:2017-09-26 02:35:46

标签: android listview

我不知道如何将我的图像从服务器显示到listview。我能够获取其他信息但不能获取图像。如果有人可以教我,真的很感激。以下是我的代码。

public class lecturer_list extends ListActivity {

    ProgressDialog progressDialog;
    private static final String TAG_POST= "posts";
    private static final String TAG_ID="lecID";
    private static final String TAG_NAME="lecName";
    private static final String TAG_EMAIL="lecEmail";
    private static final String TAG_PASS="lecPass";
    private static final String TAG_IMAGE="image";
    private static final String LECTURER_LIST_URL="http://fyp.com/lecturer_list.php";

    private JSONArray mComments =null;
    private ArrayList<HashMap<String,String>> mcommentList;

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

    }
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        new LoadComments().execute();
    }

    public void updateJSONdata(){
        mcommentList= new ArrayList<HashMap<String, String>>();
        JSONParser jsonParser=new JSONParser();
        JSONObject json=jsonParser.getJSONFromUrl(LECTURER_LIST_URL);
        try{
            mComments= json.getJSONArray(TAG_POST);
            for (int i = 0; i < mComments.length(); i++) {
                JSONObject c= mComments.getJSONObject(i);
                String lecPass=c.getString(TAG_PASS);
                String lecImage=c.getString(TAG_IMAGE);
                HashMap<String, String> map = new HashMap<String, String>();
                map.put(TAG_PASS,lecPass);
                map.put(TAG_IMAGE,lecImage);
                mcommentList.add(map);

            }

        }catch (JSONException e){
            e.printStackTrace();

        }
    }
    public void updateList(){
        ListAdapter adapter=new SimpleAdapter(this,mcommentList,R.layout.lecturer_list,
                new String[]{TAG_IMAGE,TAG_NAME,TAG_ID,TAG_PASS,TAG_EMAIL},
                new int[]{R.id.lec_Image,R.id.lecturer_Name,R.id.lec_ID,R.id.lec_Pass});
        setListAdapter(adapter);
        ListView lv=getListView();
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

      //I know this is not the correct way to fetch image.
                String lec_Image=((ImageView) view.findViewById(R.id.lec_Image)).getDrawable().toString();
                String lec_Name=((TextView) view.findViewById(R.id.lecturer_Name)).getText().toString();
            }
        });
    }

感谢您是否可以告诉我哪些方面我做错了。我缩短了我的代码。

0 个答案:

没有答案