-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,它只运行 7 次。我在做什么。请帮帮我..

4

1 回答 1

1

您可以使用以下方法之一

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

2)通用图像加载器 - https://github.com/nostra13/Android-Universal-Image-Loader

3) Volley - 如果您看过 google io-2013 视频。凌空应该非常快。

于 2013-07-23T08:21:49.393 回答