鍍金池/ 問(wèn)答/Java  Android/ popwindow嵌套了recyclerview為何不顯示內(nèi)容?

popwindow嵌套了recyclerview為何不顯示內(nèi)容?

1.popwindow嵌套了recyclerview,但是不顯示內(nèi)容

2.相關(guān)代碼如下
popwindow布局xml-------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/fl_familyList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="@+id/rl_family"
android:background="@color/colorRlBg">

<RelativeLayout
    android:id="@+id/ly_family_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_mfamily_list"
            android:layout_width="match_parent"
            android:layout_height="200dp">
        </android.support.v7.widget.RecyclerView><!--家庭列表-->


 </RelativeLayout>

</FrameLayout>

適配器代碼--------------------------------------------------------------------------
public class RvFamilyAdapter extends RecyclerView.Adapter<RvFamilyAdapter.ViewHolder>{

private List<Family> mfamilyList;

public RvFamilyAdapter(List<Family> familyList) {
    mfamilyList = familyList;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    //設(shè)置RecyclerView的源item.xml
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.family_familylist_recyclerview_item, parent, false);
    ViewHolder holder = new ViewHolder(view);
    return holder;
}

@Override
public void onBindViewHolder(@NonNull RvFamilyAdapter.ViewHolder holder, int position) {
    //通過(guò)position位置找到每個(gè)列表子項(xiàng),并用Intelligent對(duì)象存儲(chǔ)
    //為子項(xiàng)view設(shè)置屬性,值為family中存的字段
    holder.tv_family_name.setText(mfamilyList.get(position).getFamilyName());
    holder.tv_family_owner_name.setText(mfamilyList.get(position).getFamilyOwner());
}

@Override
public int getItemCount() {
    return mfamilyList.size();
}
/*ViewHolder內(nèi)部類是必須實(shí)現(xiàn)的*/
static class ViewHolder extends RecyclerView.ViewHolder {
    ImageView iv_family_is_true;
    ImageView iv_family_logo;
    TextView tv_family_name;
    TextView tv_family_character;
    TextView tv_family_owner_name;
    /*
     * 在 ViewHolder內(nèi)部類里初始化布局中的view
     * */
     ViewHolder(View itemView) {
        super(itemView);
        //注意這里的view和Activity不一樣,通過(guò)參數(shù)itemView來(lái)find
        iv_family_is_true = itemView.findViewById(R.id.iv_family_is_true);
        iv_family_logo = itemView.findViewById(R.id.iv_family_logo);
        tv_family_name = itemView.findViewById(R.id.tv_family_name);
        tv_family_character = itemView.findViewById(R.id.tv_family_character);
        tv_family_owner_name = itemView.findViewById(R.id.tv_family_owner_name);
    }
}

}

綁定適配器:-------------------------------------------------------------------------
private void handRecyList(){

    View view = LayoutInflater.from(getActivity()).inflate(R.layout.family_popwindow_view,null);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rv_mfamily_list);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(linearLayoutManager);
    family_adapter = new RvFamilyAdapter(getFamilyList());
    recyclerView.setAdapter(family_adapter);
    family_adapter.notifyDataSetChanged();
}

3.報(bào)錯(cuò)信息:RecyclerView: No adapter attached; skipping layout

4.試過(guò)很多方法如:把線性布局換成相對(duì)布局、初始化時(shí)候setadapter、更新數(shù)據(jù)源family_adapter.notifyDataSetChanged()、clean&&rebuild.........始終找不出原因,難道是因?yàn)槲野裵opwindow放在fragment中導(dǎo)致的?找了一周原因了,請(qǐng)大神們幫幫忙吧,不勝感激!

回答
編輯回答
舊酒館

我有幾個(gè)問(wèn)題想問(wèn)你,
1.recyclerview是在popwindows里面嗎?
2.你是列表的內(nèi)容不能顯示,還是popwindow根本彈不出來(lái)?

你是不是這里沒(méi)有

clipboard.png
沒(méi)有設(shè)置背景?

下面是我做的一個(gè)demo,這個(gè)是效果
clipboard.png
代碼路徑為:
https://github.com/love0829/l...

歡迎star

2017年11月13日 07:11