1

Я использую simpleAdapter для загрузки изображений и текста в autocompletetextview вместе с библиотекой Universal_Image_loader, но я не получаю изображения. Как я могу заставить его работать? Я очень ценю любую помощь. Спасибо в Advance.image not loading in baseadapter

public class SimpleAdapter extends BaseAdapter { 

     private Activity activity; 
     private ArrayList<HashMap<String, String>> data; 
     private static LayoutInflater inflater=null; 
     public ImageLoader imageLoader ; 
     Bitmap image; 
     private DisplayImageOptions defaultOptions; 

     public SimpleAdapter(Activity a, ArrayList<HashMap<String, String>> d) { 
      activity = a; 
      data=d; 
      inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

// imageLoader=new ImageLoader(activity.getBaseContext()); 
      defaultOptions = new DisplayImageOptions.Builder().build(); 

      ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(activity) 
      .threadPoolSize(2) 
      .memoryCache(new WeakMemoryCache()) 
      .discCacheFileNameGenerator(new Md5FileNameGenerator()) 
      .build(); 

      imageLoader = ImageLoader.getInstance(); 

     imageLoader.init(config); 

      imageLoader.init(ImageLoaderConfiguration.createDefault(activity)); 
     } 

     public int getCount() { 
      return data.size(); 
     } 

     public Object getItem(int position) { 
      return position; 
     } 

     public long getItemId(int position) { 
      return position; 
     } 

     public View getView(int position, View convertView, ViewGroup parent) { 
      View vi=convertView; 
      if(convertView==null) 
       vi = inflater.inflate(R.layout.list_row, null); 

      TextView title = (TextView)vi.findViewById(R.id.textView1); // title 
      TextView artist = (TextView)vi.findViewById(R.id.textView2); // artist name 
      TextView duration = (TextView)vi.findViewById(R.id.textView3); // duration 
      ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image 

      HashMap<String, String> song = new HashMap<String, String>(); 
      song = data.get(position); 

      // Setting all values in listview 
      title.setText(song.get("firstname")); 
      artist.setText(song.get("lastname")); 
      duration.setText(song.get("time")); 
      imageLoader.displayImage(song.get("link"), thumb_image, defaultOptions); 

      return vi; 
     } 


    } 

//////

код: //

List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>(); 

      try{ 
       JSONArray arr=result.getJSONArray("Array"); 


      for(int i=0;i<arr.length();i++) 
      { 
       JSONObject e1 = arr.getJSONObject(i); 

       JSONObject json= (JSONObject) e1.get("data"); 

       String firstname = json.getString("firstname").trim(); 
       String lastname = json.getString("lastname").trim(); 
       String link = json.getString("link").trim(); 
       String time = json.getString("time").trim(); 


       HashMap<String, String> hm = new HashMap<String,String>(); 
        hm.put("firstname", firstname); 
        hm.put("lastname", lastname); 
        hm.put("link", link); 
        hm.put("time", time); 
        aList.add(hm); 

       } 


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

      } 


      String[] from = { "firstname","lastname","time","link"}; 


      int[] to = { R.id.textView1,R.id.textView2,R.id.textView3,R.id.list_image}; 

      adapter = new SimpleAdapter(AutoCompleteTextViewActivity.this,aList, R.layout.list_row,from,to); 

       actv.setAdapter(adapter); 

       adapter.notifyDataSetChanged(); 
+1

Вы можете дать мне один из valer of song.get ("link") –

+0

Необходимо проверить, что изображение является ключевым. – Piyush

+0

что-то вроде этого https://fbcdn-sphotos-ea.akamaihd.net/hphotos-ak-frc3/p403x403/1482967_10152149744701214_1208231620_n.jpg – jason

ответ

1

вы должны использовать

imageLoader=new ImageLoader(activity); 

вместо

imageLoader=new ImageLoader(activity.getBaseContext()); 

Изменение здесь также

private Activity activity; 

в

private Context activity; 

также здесь от

public SimpleAdapter(Activity a, ArrayList<HashMap<String, String>> d) 

в

public SimpleAdapter(Context a, ArrayList<HashMap<String, String>> d) 
+0

Я получаю 'Конструктор ImageLoader (Activity) undefined', когда добавляю' imageLoader = new ImageLoader (activity); ' – jason

+0

Проверьте мой обновленный ответ. – Piyush

+0

Я все еще получаю ту же ошибку. 'Конструктор ImageLoader (Activity) не определен' – jason

0

попробуйте использовать

imageLoader=new ImageLoader(activity.getApplicationContext());