2013-07-23 156 views
-3
class LoadLatest extends AsyncTask<String,Void,String>{ 

    ProgressDialog mProgress; 

@Override 
protected void onPreExecute() { 

    mProgress=new ProgressDialog(MainActivity.mContext); 
    mProgress.setTitle("Fetech Latest Videos"); 
    mProgress.setMessage("Please Wait..."); 
    mProgress.setCancelable(false); 
    mProgress.show(); 
} 


    @Override 
    protected String doInBackground(String... params) { 

     try{ 
      JSONParser jParser = new JSONParser(); 
      String url="http://twominenglish.com/api/getlatest?"; 
      //http://twominenglish.com/api/getlatest?page=1 
      JSONArray IdArray = jParser.getJSONFromUrl(url+"page="+page); 
      mLatestList.clear(); 
      for(int i=0;i<IdArray.length();i++){ 

       try{ 
        JSONObject jObject; 
        mLtest=new Latest(); 
        jObject=IdArray.getJSONObject(i); 
        mLtest.SetID(jObject.getString("ID")); 
        //mLtest.SetImageUrl(jObject.getString("ImageURL")); 
        String path="http://twominenglish.com"+jObject.getString("ImageURL"); 
        mLtest.SetImageUrl(path); 
        mLtest.SetDescription(jObject.getString("Description")); 
        mLtest.SetTitle(jObject.getString("Title")); 
        mLatestList.add(mLtest); 
        mLtest=new Latest(); 
       }catch(JSONException e){ 
        e.printStackTrace(); 
       } 
      } 


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

     } 


     // TODO Auto-generated method stub 
     return null; 
    } 

//我的適配器類如何從服務器獲取圖像

public class LatestAdapter extends BaseAdapter{ 


private static ArrayList<Latest> ArrayList; 
private Activity activity; 
private LayoutInflater mInflater=null; 
private Context mContext; 
AvatarDownloader ad; 
public ImageLoader mImageLoader; 
public LatestAdapter(Activity context, ArrayList<Latest> results) { 
    activity =context; 
    ArrayList = results; 
    mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    //mContext=context; 
    mImageLoader=new ImageLoader(context.getApplicationContext()); 
} 

@Override 
public int getCount() { 
    // TODO Auto-generated method stub 
    return ArrayList.size(); 
} 

@Override 
public Object getItem(int position) { 
    // TODO Auto-generated method stub 
    return ArrayList.get(position); 
} 

@Override 
public long getItemId(int position) { 
    // TODO Auto-generated method stub 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
    final ViewHolder holder; 
    if (convertView == null) { 
     convertView = mInflater.inflate(R.layout.latest_category, null); 
     holder = new ViewHolder(); 

     holder.tv_Title = (TextView) convertView.findViewById(R.id.txtsubcatTitle);   
     holder.imgvw_pic = (ImageView) convertView.findViewById(R.id.imageView_pic); 
     //ad=new AvatarDownloader(mContext); 
     mImageLoader=new ImageLoader(activity); 
     mImageLoader.DisplayImage(ArrayList.get(position).GetImageUrl(), ArrayList.get(position).GetTitle(), null, holder.imgvw_pic); 
     String url=ArrayList.get(position).GetImageUrl().toString(); 
     convertView.setTag(holder); 
    } else { 
     holder = (ViewHolder) convertView.getTag(); 
    } 

    holder.tv_Title.setText(ArrayList.get(position).GetTitle()); 



    return convertView; 
} 

static class ViewHolder { 
    TextView tv_Title; 
    ImageView imgvw_pic; 
} 

誰能幫這是它採取從ArrayList中20 URL我的適配器類時,我fetech通過圖像加載它只能運行圖像僅7次。我do.please幫助我..

+1

看看Volley:https://developers.google.com/events/io/sessions/325304728 – EvZ

+0

@shreyas我把我的代碼請幫助我。我有20個網址,當我fetech形象它只會7次只有在哪裏,請幫助我。 – Ali786

+0

@ EvZ-我把我的代碼請幫助我。我有20個網址,當我fetech形象它將只有7次只有在哪裏請柬幫助我 – Ali786

回答

1

您可以使用該

1)LAZY列表 - https://github.com/thest1/LazyList

2)通用圖像加載如下因素之一 - https://github.com/nostra13/Android-Universal-Image-Loader

3)排球 - 如果你看到谷歌io-2013視頻。凌空應該很快。

+0

-i已經使用LazyList代碼下載images.i不知道在哪裏是prblm爲什麼不下載所有的圖像,請檢查我已經發布在這裏的代碼-http://stackoverflow.com/questions/17785437/how-to-解析器-json-for-image-url/17802412?noredirect = 1#17802412等待你的回覆,謝謝你很多 – Ali786

+0

爲什麼你不使用懶惰列表,因爲它是... – shreyas