Android 加载时具有微秒延迟的复杂项的Listview

Android 加载时具有微秒延迟的复杂项的Listview,android,jquery,listview,Android,Jquery,Listview,我花了两天时间试图找到这个问题的解决方案,但在任何地方都找不到。我的问题是:我有一个列表视图,其中每个项目有4个文本视图和一个图像视图。我正在使用截击从网站获取数据。数据加载正常,当我向下滚动时,一切正常。问题是当我向后滚动时。当我向后滚动时,图像和文本视图的显示延迟为0.5(首先我看到最后一项的图片),然后显示内容。我已经尝试过使用viewholder的recyclerview和listview。这一“轻弹”在两种解决方案中都存在 public class BigCategoryListVie

我花了两天时间试图找到这个问题的解决方案,但在任何地方都找不到。我的问题是:我有一个列表视图,其中每个项目有4个文本视图和一个图像视图。我正在使用截击从网站获取数据。数据加载正常,当我向下滚动时,一切正常。问题是当我向后滚动时。当我向后滚动时,图像和文本视图的显示延迟为0.5(首先我看到最后一项的图片),然后显示内容。我已经尝试过使用viewholder的recyclerview和listview。这一“轻弹”在两种解决方案中都存在

public class BigCategoryListViewAdapter extends BaseAdapter{

    private Context context;
    private String[] smallCatsList;
    private News news;
    private ImageLoader imageLoader;

    static class myViewHolder{
    TextView smallCatName;
    RelativeLayout spinner;
    ImageView newsImageView;
    TextView newsTitle;
    TextView newsContent;


}

public BigCategoryListViewAdapter(Context context, String[] smallCatsList){
    this.context = context;
    this.smallCatsList = smallCatsList;
    this.imageLoader = ImageLoader.getInstance();
    if(!this.imageLoader.isInited()) {  this.imageLoader.init(ImageLoaderConfiguration.createDefault(context));}
}

@Override
public int getCount() {
    return smallCatsList.length;
}

@Override
public Object getItem(int position) {
    return smallCatsList[position];
}

@Override
public long getItemId(int position) {return 0;} //modificar aqui



@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final myViewHolder mvh;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);



    convertView = inflater.inflate(R.layout.bigcat_listview,null);

    mvh = new myViewHolder();

    mvh.smallCatName = (TextView) convertView.findViewById(R.id.bigcat_viewpager_smallcat);
    mvh.spinner = (RelativeLayout) convertView.findViewById(R.id.spinner);
    mvh.newsImageView = (ImageView) convertView.findViewById(R.id.bigcat_viewpager_imageView);
    mvh.newsTitle = (TextView) convertView.findViewById(R.id.bigcat_viewpager_news_title);
    mvh.newsContent = (TextView) convertView.findViewById(R.id.bigcat_viewpager_content);
    convertView.setTag(mvh);


    mvh.smallCatName.setText(smallCatsList[position]);

    JSONObject params = new JSONObject();
    try{
        params.put("slug",smallCatsList[position]);
        params.put("startIndex", 0);
        params.put("endIndex", 0);
    }catch (Exception e) {
        Log.e(getClass().toString(), "Error setting params for communication with server");
        e.printStackTrace();
    }

    Volley volley = Volley.getVolley(context);
    volley.runRequest(Request.Method.POST, VolleyConstants.PROD_URL + VolleyConstants.NEWS_FETCH_ROUTE,
        params, new Response.Listener<JSONObject>() {
        //---------------------Volley------------------//

    @Override
        public void onResponse(JSONObject response) {
            JSONArray responseArr = null;
            try {
                responseArr = response.getJSONArray("newsArr");
            } catch (Exception e) {
                e.printStackTrace();
            }

            for (int i = 0; i < responseArr.length(); i++) {
                try {
                    JSONObject object = responseArr.getJSONObject(i);
                    String photoURLString = object.getString("photo");
                    String titleString = object.getString("title");
                    String publisherString = object.getString("publisher");
                    String dateString = object.getJSONObject("date").getString("date");
                    String contentString = object.getString("contents");
                    String urlString = object.getString("url");

                    news = new News(photoURLString, titleString, publisherString, dateString, contentString,urlString);
                } catch (Exception e) {
                    news = new News("Unknown", "Unknown", "Unknown", "Unknown", "Unknown","Unknown");
                }




            }
            //tv2.setText(news.getNewsDate());

            mvh.newsContent.setText(news.getNewsContent());
            mvh.newsTitle.setText(news.getNewsHead());

            //---------------------Image Loading------------------//
            try {
                URL url = new URL(news.getNewsPic());
                imageLoader.loadImage(news.getNewsPic(), new ImageLoadingListener() {
                @Override
                    public void onLoadingStarted(String imageUri, View view) {

                    }

                @Override
                    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

                    }

                @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                        mvh.newsImageView.setImageBitmap(loadedImage);
                        mvh.spinner.setVisibility(View.GONE);
                    }

                @Override
                    public void onLoadingCancelled(String imageUri, View view) {


                    }
                });
            }catch(Exception e){
                mvh.newsImageView.setImageDrawable(context.getResources().getDrawable(R.drawable.nopic));
                mvh.spinner.setVisibility(View.GONE);

            }


        }
    }, new CustomErrorListener("ERROR"));

    return convertView;
}
公共类BigCategoryListViewAdapter扩展了BaseAdapter{
私人语境;
私有字符串[]smallCatsList;
私人新闻;
私有图像加载器;
静态类myViewHolder{
文本视图smallCatName;
相对长度微调器;
ImageView新闻ImageView;
文本视图新闻标题;
文本视图新闻内容;
}
公共BigCategoryListViewAdapter(上下文上下文,字符串[]smallCatsList){
this.context=上下文;
this.smallCatsList=smallCatsList;
this.imageLoader=imageLoader.getInstance();
如果(!this.imageLoader.isInited()){this.imageLoader.init(ImageLoaderConfiguration.createDefault(context));}
}
@凌驾
public int getCount(){
返回smallCatsList.length;
}
@凌驾
公共对象getItem(int位置){
返回smallCatsList[位置];
}
@凌驾
公共长getItemId(int位置){return 0;}//modificar aqui
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
最终myViewHolder mvh;
LayoutFlater充气器=(LayoutFlater)context.getSystemService(context.LAYOUT\u充气器\u服务);
convertView=充气机。充气(R.layout.bigcat_列表视图,空);
mvh=新的myViewHolder();
mvh.smallCatName=(TextView)convertView.findViewById(R.id.bigcat\u viewpager\u smallcat);
mvh.spinner=(RelativeLayout)convertView.findViewById(R.id.spinner);
mvh.newsImageView=(ImageView)convertView.findViewById(R.id.bigcat_viewpager_ImageView);
mvh.newsttitle=(TextView)convertView.findViewById(R.id.bigcat\u viewpager\u news\u title);
mvh.newcontent=(TextView)convertView.findViewById(R.id.bigcat_viewpager_content);
convertView.setTag(mvh);
mvh.smallCatName.setText(smallCatsList[position]);
JSONObject参数=新的JSONObject();
试一试{
参数put(“slug”,smallCatsList[位置]);
参数put(“startIndex”,0);
参数put(“endIndex”,0);
}捕获(例外e){
Log.e(getClass().toString(),“设置与服务器通信的参数时出错”);
e、 printStackTrace();
}
截击=截击。截击(上下文);
volley.runRequest(Request.Method.POST,VolleyConstants.PROD\u URL+VolleyConstants.NEWS\u FETCH\u路由,
params,新的Response.Listener(){
//---------------------截击------------------//
@凌驾
公共void onResponse(JSONObject响应){
JSONArray responseArr=null;
试一试{
responseArr=response.getJSONArray(“newsArr”);
}捕获(例外e){
e、 printStackTrace();
}
对于(int i=0;i
这是我的适配器。我的问题是,是否有办法消除此延迟以显示内容?还是我的网络或listview本身存在问题?
我只想加载所有内容一次,然后用户可以上下滚动,而无需每次刷新内容。

每次调用getView时都要加载内容,这就是为什么它会这样加载。将截击请求与getView分开,它应该在
if (convertView == null) {
    convertView = inflater.inflate(R.layout.bigcat_listview,null);

    mvh = new myViewHolder();
    //... rest of your code
} else {
    mvh = (myViewHolder) convertView.getTag();
    //... rest of your code
}