android – SwipeRefreshLayout中的Listview – 当自定义适配器只显示一行时,不会显示任何内容

android – SwipeRefreshLayout中的Listview – 当自定义适配器只显示一行时,不会显示任何内容,第1张

概述在我的应用程序中,我有一个列表视图.当我有多个项目展示时,所有的东西都能很好地工作,但是当我在列表视图中显示一个项目时,它会向我显示一个罕见的行为. 首先:如果单个物品的高度大于窗户高度……它就像一个魅力并且正常工作.(A) 第二:如果单个项目的高度小于窗口高度…有时它显示项目(B),有时则不显示! (C). 第三:我正在使用SwipeRefreshLayout from支持库,当我尝试刷新lis 在我的应用程序中,我有一个列表视图.当我有多个项目展示时,所有的东西都能很好地工作,但是当我在列表视图中显示一个项目时,它会向我显示一个罕见的行为.

首先:如果单个物品的高度大于窗户高度……它就像一个魅力并且正常工作.(A)

第二:如果单个项目的高度小于窗口高度…有时它显示项目(B),有时则不显示! (C).

第三:我正在使用SwipeRefreshLayout from支持库,当我尝试刷新ListvIEw时,如果我在ListvIEw中有一个项目…如果它的高度小于窗口高度,它不会显示该项目.(C)

我想不出来!!有谁能够帮我

我知道这个问题与SwipeRefreshLayout或ListvIEw的高度有关,因为当我将margintop设置为此视图(作为屏幕高度的一半)时,ListvIEw的工作原理是perefctly.

我的xml文件是:

 

<androID.support.v4.Widget.SwipeRefreshLayoutandroID:ID="@+ID/swipe_Container"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:layout_margintop="0dp"androID:background="#FFedf1f2"androID:paddingleft="8.5dp"androID:paddingRight="8.5dp"androID:paddingtop="0dp" ><ListVIEw    androID:ID="@+ID/List"    androID:layout_wIDth="match_parent"    androID:layout_height="0dp"    androID:layout_weight="1"    androID:divIDer="@androID:color/transparent"    androID:divIDerHeight="8.5dp"    androID:scrollbars="none" ></ListVIEw>@H_404_26@  

 

一切都像魅力一样,直到我在ListvIEw中显示至少多一个项目.但是当我在列表视图中显示一个项目时,我的列表视图没有显示任何内容:(

为什么?我的错在哪里?我哪里错了?

这是我的适配器的getVIEw()(扩展BaseAdapter – 我已经削减了一些代码行):

public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {    Typeface MyriadRegular  = Farsi.GetMyriadRegular(mActivity);    Typeface MyriadBold     = Farsi.GetMyriadBold(mActivity);    Typeface Yagut          = Farsi.GetYagut(mActivity);    Typeface JalalBold      = Farsi.GetJalalBold(mActivity);    User_Session            = new SessionManagement(mActivity);    VIEw row    = convertVIEw;    VIEwHolder holder;    mVIDeo              = mData.get(position);    //======================================================================== USER    USERname            = mVIDeo.get("USERname").toupperCase();    CHANNEL_name        = mVIDeo.get("CHANNEL_name");    CHANNEL_ID          = mVIDeo.get("CHANNEL_ID");    USER_ID             = mVIDeo.get("USER_ID");    AVATAR              = mVIDeo.get("AVATAR");    //======================================================================== VIDEO    VIDEO_URL           = mVIDeo.get("VIDEO_URL");    Title               = mVIDeo.get("Title");    DESCRIPTION         = mVIDeo.get("DESCRIPTION");    BIG_IMAGE           = mVIDeo.get("BIG_IMAGE");    VIEW_CNT            = mVIDeo.get("VIEW_CNT");    COMMENT_CNT         = mVIDeo.get("COMMENT_CNT");    liKE_CNT            = mVIDeo.get("liKE_CNT");    liKE_COUNT          = Integer.parseInt(liKE_CNT);    disliKE_CNT         = mVIDeo.get("disliKE_CNT");    disliKE_COUNT       = Integer.parseInt(disliKE_CNT);    POST_DATE           = mVIDeo.get("POST_DATE");    DURATION            = mVIDeo.get("DURATION");    category_Title      = mVIDeo.get("category_Title");    category_ID         = mVIDeo.get("category_ID");    VIDEO_ID            = mVIDeo.get("VIDEO_ID");    VIDEO_WEB           = mVIDeo.get("VIDEO_WEB");    liKE_W_USER         = mVIDeo.get("liKE_W_USER");    disliKE_W_USER      = mVIDeo.get("disliKE_W_USER");    Follow_B_USER       = mVIDeo.get("FolLOW_B_USER");    like_with_user      = Boolean.parseBoolean(liKE_W_USER);    dislike_with_user   = Boolean.parseBoolean(disliKE_W_USER);    FolLOW_BY_USER      = Boolean.parseBoolean(Follow_B_USER);    if(convertVIEw == null) {        row     = mInflater.inflate(R.layout.layout_List_row,parent,false);        holder  = new VIEwHolder(row);        row.setTag(holder);    }else{        row     = convertVIEw;        holder  = (VIEwHolder) row.getTag();    }    holder.user_Avatar.setTag(USER_ID);    holder.user_name.setTag(USER_ID);    holder.user_Avatar.setonClickListener(ChannelProfile);    holder.user_name.setonClickListener(ChannelProfile);    holder.vIDeo_Comment.setTag(position);    holder.vIDeo_like.setTag(R.string.position,position);    holder.vIDeo_like.setTag(R.string.VIDeo_ID,VIDEO_ID);    holder.vIDeo_dislike.setTag(R.string.position,position);    holder.vIDeo_dislike.setTag(R.string.VIDeo_ID,VIDEO_ID);    holder.vIDeo_Edit.setTag(position);    holder.vIDeo_Delete.setTag(position);    holder.vIDeo_editText.setTypeface(JalalBold);    holder.vIDeo_deleteText.setTypeface(JalalBold);    if (!mNext.equals("NONE")){        if (position >= getCount() - 1){            if(mSwipe != null){                mSwipe.setRefreshing(true);            }            loadmore();        }    }    holder.vIDeo_Duration.setTypeface(MyriadBold);    holder.vIDeo_Duration.setText(Farsi.Convert(DURATION));    holder.vIDeo_Title.setTypeface(Yagut);    holder.vIDeo_Title.setText(Title);    holder.user_name.setTypeface(MyriadRegular);    holder.user_name.setText(CHANNEL_name);    holder.vIDeo_Description.setTypeface(MyriadRegular);    holder.vIDeo_Description.setText(DESCRIPTION);    holder.vIDeo_Description.setClickable(true);    holder.vIDeo_categoryTitle.setTypeface(JalalBold);    holder.vIDeo_categoryTitle.setText(category_Title);    holder.vIDeo_VIEwCount.setTypeface(JalalBold);    holder.vIDeo_VIEwCount.setText(VIEW_CNT);    holder.vIDeo_CommentCount.setTypeface(JalalBold);    return row;}@H_404_26@  

Edite:这是我的vIEwHolder类:

静态类VIEwHolder {

TextVIEw            vIDeo_Duration;    TextVIEw            vIDeo_Title;    ExpandableTextVIEw  vIDeo_Description;    TextVIEw            vIDeo_categoryTitle;    TextVIEw            vIDeo_VIEwCount;    TextVIEw            vIDeo_PostDate;    TextVIEw            vIDeo_likeCount;    TextVIEw            vIDeo_CommentCount;    TextVIEw            vIDeo_dislikeCount;    TextVIEw            vIDeo_editText;    TextVIEw            vIDeo_deleteText;    ImageVIEw           vIDeo_BigImage;    button              vIDeo_like;    button              vIDeo_dislike;    button              vIDeo_Comment;    relativeLayout      vIDeo_options;    relativeLayout      vIDeo_Edit;    relativeLayout      vIDeo_Delete;    //=================================    TextVIEw            user_name;    ImageVIEw           user_Avatar;    public VIEwHolder(VIEw vi) {        vIDeo_Duration      = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_Duration);        vIDeo_Title         = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_Title);        vIDeo_Description   = (ExpandableTextVIEw) vi.findVIEwByID(R.ID.vIDeo_Description);        vIDeo_categoryTitle = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_category_Title);        vIDeo_VIEwCount     = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_VIEw_Count);        vIDeo_PostDate      = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_Post_Date);        vIDeo_likeCount     = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_like_cnt);        vIDeo_CommentCount  = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_Comment_cnt);        vIDeo_dislikeCount  = (TextVIEw) vi.findVIEwByID(R.ID.vIDeo_dislike_cnt);        vIDeo_editText      = (TextVIEw) vi.findVIEwByID(R.ID.edit_text);        vIDeo_deleteText    = (TextVIEw) vi.findVIEwByID(R.ID.delete_text);        vIDeo_BigImage      = (ImageVIEw) vi.findVIEwByID(R.ID.vIDeo_Image);        vIDeo_like          = (button) vi.findVIEwByID(R.ID.vIDeo_like);        vIDeo_dislike       = (button) vi.findVIEwByID(R.ID.vIDeo_dislike);        vIDeo_Comment       = (button) vi.findVIEwByID(R.ID.vIDeo_Comment);        vIDeo_options       = (relativeLayout) vi.findVIEwByID(R.ID.vIDeoOptions);        vIDeo_Edit          = (relativeLayout) vi.findVIEwByID(R.ID.vIDeoEditBtn);        vIDeo_Delete        = (relativeLayout) vi.findVIEwByID(R.ID.vIDeoDeleteBtn);        user_name           = (TextVIEw) vi.findVIEwByID(R.ID.username);        user_Avatar         = (ImageVIEw) vi.findVIEwByID(R.ID.user_avatar);    }}@H_404_26@  

JsON解析部分(我正在使用ION库进行异步网络):

private voID initSearch(String tag,boolean refresh){    final boolean Refornormal = refresh;    URL = Constants.Search_URL+tag;    if(User_Session.isLoggedIn()){        URL = Constants.Search_URL+tag+"&token="+User_TOKEN;    }    System.out.println("URL: "+URL);    if (VIDeoload != null && !VIDeoload.isDone() && !VIDeoload.isCancelled()) return;    VIDeoload   = Ion.with(this).load(URL).asJsonObject().setCallback(new FutureCallback<JsonObject>() {        @OverrIDe        public voID onCompleted(Exception e,JsonObject result) {            if (Refornormal == true){                mAdapter.clearData();            }            if ( e == null){                System.out.println("RESulT: "+result);                VIDeos  = result.getAsJsonArray("objects");                if(VIDeos.size() > 0){                    for (int i = 0; i < VIDeos.size(); i++) {                        JsonObject Item = VIDeos.get(i).getAsJsonObject();                        //======================================================================== USER                        USERname        = Item.get("username").getAsstring();                        CHANNEL_name    = Item.get("channel_name").getAsstring();                        CHANNEL_ID      = Item.get("channel_ID").getAsstring();                        USER_ID         = Item.get("user_ID").getAsstring();                        AVATAR          = Item.get("avatar").getAsstring();                        //======================================================================== VIDEO                        VIDEO_URL       = Item.get("vIDeo_url").getAsstring();                        Title           = Item.get("Title").getAsstring();                        DESCRIPTION     = Item.get("text").getAsstring();                        BIG_IMAGE       = Item.get("image").getAsstring();                        VIEW_CNT        = Item.get("cnt_vIEw").getAsstring();                        COMMENT_CNT     = Item.get("cnt_comment").getAsstring();                        liKE_CNT        = Item.get("cnt_like").getAsstring();                        disliKE_CNT     = Item.get("cnt_dislike").getAsstring();                        POST_DATE       = Item.get("create_time").getAsstring();                        DURATION        = Item.get("duration").getAsstring();                        category_Title  = Item.get("category_Title").getAsstring();                        category_ID     = Item.get("category_ID").toString();                        VIDEO_ID        = Item.get("ID").getAsstring();                        VIDEO_WEB       = Item.get("web_url").getAsstring();                        liKE_W_USER     = Item.get("like_with_user").getAsstring();                        disliKE_W_USER  = Item.get("dislike_with_user").getAsstring();                        Follow_B_USER   = Item.get("follow_by_user").getAsstring();                        HashMap<String,String> Items = new HashMap<String,String>();                        Items.put("USERname",USERname);                        Items.put("CHANNEL_name",CHANNEL_name);                        Items.put("CHANNEL_ID",CHANNEL_ID);                        Items.put("USER_ID",USER_ID);                        Items.put("AVATAR",AVATAR);                        Items.put("VIDEO_URL",VIDEO_URL);                        Items.put("Title",Title);                        Items.put("DESCRIPTION",DESCRIPTION);                        Items.put("BIG_IMAGE",BIG_IMAGE);                        Items.put("VIEW_CNT",VIEW_CNT);                        Items.put("COMMENT_CNT",COMMENT_CNT);                        Items.put("liKE_CNT",liKE_CNT);                        Items.put("disliKE_CNT",disliKE_CNT);                        Items.put("POST_DATE",POST_DATE);                        Items.put("DURATION",DURATION);                        Items.put("category_Title",category_Title);                        Items.put("category_ID",category_ID);                        Items.put("VIDEO_ID",VIDEO_ID);                        Items.put("VIDEO_WEB",VIDEO_WEB);                        Items.put("liKE_W_USER",liKE_W_USER);                        Items.put("disliKE_W_USER",disliKE_W_USER);                        Items.put("Follow_B_USER",Follow_B_USER);                        DATA.add(Items);                    }                    Page            = result.getAsJsonObject("Meta");                    if(User_Session.isLoggedIn()){                        HashMap<String,String> user    = User_Session.GetUserDetails();                        String User_TOKEN               = user.get(SessionManagement.KEY_USERTOKEN);                        if(Page.equals("")){                            NextPage    = "NONE";                        }else{                            NextPage    = Page.get("next").getAsstring()+"&token="+User_TOKEN;                        }                    }else{                        if(Page.equals("")){                            NextPage    = "NONE";                        }else{                            NextPage    = Page.get("next").getAsstring();                        }                    }                    mAdapter = new MyCustomAdapter(SearchActivity.this,DATA,NextPage,ParsvIDswipeLayout,false,"");                    List.setAdapter(mAdapter);                    mAdapter.notifyDataSetChanged();                    new Handler().postDelayed(new Runnable() {                        @OverrIDe                        public voID run() {                            ParsvIDswipeLayout.setRefreshing(false);                        }                    },500);                }else{                    new Handler().postDelayed(new Runnable() {                        @OverrIDe                        public voID run() {                            ParsvIDswipeLayout.setRefreshing(false);                        }                    },500);                }            }        }    });}@H_404_26@解决方法 问题在于您每次都在创建新适配器而不是向适配器添加数据  

mAdapter = new MyCustomAdapter(SearchActivity.this,"");                     List.setAdapter(mAdapter);                     mAdapter.notifyDataSetChanged();@H_404_26@  

只需使用适配器中的方法addAll()添加数据即可.在每次数据加载时都不需要一次又一次地更换适配器.

我在你的代码中发现了这个问题.

总结

以上是内存溢出为你收集整理的android – SwipeRefreshLayout中的Listview – 当自定义适配器只显示一行时,不会显示任何内容全部内容,希望文章能够帮你解决android – SwipeRefreshLayout中的Listview – 当自定义适配器只显示一行时,不会显示任何内容所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1127692.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存