当前位置: 首页 > 知识库问答 >
问题:

FirebaseRecyclerAdaptor不会填充recyclerview

狄英哲
2023-03-14

您好,我对firebase比较陌生,我已经看到了firebase RecolyerView适配器用于Fragment的新实现。我的问题是应用程序不会填充我的回收视图。这是我的代码

我的碎片

public class DummyFragment extends android.support.v4.app.Fragment {
private FirebaseRecyclerAdapter<Product, ProductViewHolder> mFirebaseAdapter;
private RecyclerView mProduceList = null;
private View rootView;
private Context c;
private LinearLayoutManager manager;

public DummyFragment() {}
public static DummyFragment newInstance() {
    DummyFragment fragment = new DummyFragment();
    return fragment;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.dummy_fragment, container, false);
    FirebaseApp.initializeApp(c);
    mProduceList = rootView.findViewById(R.id.recyclerView);
    mProduceList.hasFixedSize();
    mProduceList.setLayoutManager(new LinearLayoutManager(getActivity()));
    DatabaseReference productRef = FirebaseDatabase.getInstance().getReference().child("Product1");
    Query productQuery = productRef.orderByKey();

    FirebaseRecyclerOptions productOptions = new FirebaseRecyclerOptions.Builder<Product>().setQuery(productQuery, Product.class).build();

    mFirebaseAdapter = new FirebaseRecyclerAdapter<Product, ProductViewHolder>(productOptions) {
        @Override
        public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View rootView = LayoutInflater.from(c).inflate(R.layout.dummy_fragment, parent, false);
            return new ProductViewHolder(rootView);
        }

        @Override
        protected void onBindViewHolder(ProductViewHolder viewHolder, int position, Product model) {
            viewHolder.setTitle(model.getTitle());
            viewHolder.setDesc(model.getDesc());
        }
    };
    mProduceList.setAdapter(mFirebaseAdapter);
    return rootView;
};
@Override
public void onStart() {
    super.onStart();
    mFirebaseAdapter.startListening();
}

@Override
public void onStop() {
    super.onStop();
    mFirebaseAdapter.stopListening();
}
public static class ProductViewHolder extends RecyclerView.ViewHolder {

    View mView;
    public ProductViewHolder(View itemView) {
        super(itemView);
        mView = itemView;
    }
    public void setTitle(String name) {
        TextView post_name = (TextView) mView.findViewById(R.id.productTitle);
        post_name.setText(name);
    }
    public void setDesc(String type) {
        TextView post_type = (TextView) mView.findViewById(R.id.productDesc);
        post_type.setText(type);
    }
}
}

产品类别

public class Product {
String Title,Description;
private String image;
public Product(){}

public Product(String title,String desc, String image){
    Title = title;
    Description = desc;
    this.image = image;
}
public String getTitle() {
    return Title;
}

public void setTitle(String title) {
    Title = title;
}

public String getDesc() {
    return Description;
}

public void setDesc(String desc) {
    Description = desc;
}

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}
}

还有我的舱单

<?xml version="1.0" encoding="utf-8"?>

null

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.DayNight.NoActionBar">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>

我看不出为什么它不会填充recyclerview的原因,但我想我遗漏了一些东西。这是我在控制台中也有的一条消息,w/fa:Service connection Failed:ConnectionResult{statuscode=service_version_update_required,resolution=null,message=null}I/fa:找不到标记管理器,因此不会使用d/fa:日志记录事件(FE):screen_view(_vs),bundle[{firebase_event_origin(_o)=auto,firebase_screen_class(_sc)=mainactivity,需要11910000但找到9879470 V/FA:正在处理排队的服务任务:4 E/FA:正在丢弃数据。无法发送应用程序启动E/FA:无法获取应用程序实例id E/FA:无法将当前屏幕发送到服务E/FA:正在丢弃数据.无法将事件发送到服务[03-15 00:06:26.003 539 9:5417D/]HostConnection::Get()建立了新的主机连接0x98C0AC40,tid 5417

共有2个答案

晋俊贤
2023-03-14

要解决这个问题,请删除后面的代码行:

mProduceList.hasFixedSize();

更多信息,请在GitHub上找到这个类似问题的答案。

海新霁
2023-03-14

请执行以下操作之一:

  1. 大多数Firebase服务都需要更新的Google Play服务,所以您需要在android模拟器上测试它,而不是Geneymotion模拟器。
  2. 如果您正在使用电话身份验证,您的唯一选择是使用真实设备。
  3. 有时您需要更新您的实际设备Google play Services:为此,最简单的方法是使用一个名为:play Services Info
  4. 的应用程序
 类似资料:
  • 当创建一个应用时,你将会想将多个控件放入一个窗口控件。我们的第一个 helloworld 范例仅仅使用了一个控件,因而我们可以只是简单地调用一个gtk_container_add()将控件填充到一个窗口控件。但是当你想要向窗口控件中放置超过一个控件时,控制每一个控件的位置和大小就变得很重要了。这就是接下来要讲的填充。 GTK+自带了大量各种布局的容器,这些容器的目的是控制被添加到他们的子控件的布局

  • 问题内容: 我正在尝试使用来自Web服务的数据填充jqGrid。我已经仔细研究了jqGrid代码和文档。我需要另一双眼睛看下面的代码,并告诉我是否缺少某些内容。 正如您将在代码中看到的那样,我将网格设置为在页面加载时或刷新期间加载。加载网格后,我再次调用Ajax以获取JSON数据并显示在网格下方的div中。 我看到了大多数预期的行为。页面加载后,网格显示加载指示器,然后启动Ajax调用,并且JSO

  • 问题内容: 我已经编写了这段代码来显示面板上的一些颜色: 正确位置和正确尺寸的两个第一面板。但是最后一个将所有帧填充为蓝色。怎么了? 问题答案: 您必须使用适当的布局管理器。默认情况下,JFrame有一个。 查看本教程的LayoutManagers: http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

  • 我正在制作一个使用tableView的程序。一切都进行得很顺利,只是由于某些原因,我无法获得要填充到表中的整数值。下面是我在主程序中的代码,当我运行程序时,字符串和Double填充,但整数没有。在我的产品类中,sku是int。不太确定哪里出了问题,寻找一些洞察力! 这里是发票对象和添加产品。

  • 主要内容:创建索引在本节中,我们将向Elasticsearch添加一些索引,映射和数据。此数据将用于本教程中解释的示例中。 创建索引 请求正文 它可以包含索引特定的设置,但是现在,它的默认设置为空。 响应 这意味着创建索引成功 创建映射和添加数据 Elasticsearch将根据请求体中提供的数据自动创建映射,我们将使用其批量功能在此索引中添加多个JSON对象。 请求体 响应结果 - 添加另一个索引 创建索引 请求

  • 元素用于在其内容周围添加填充或额外空间。 它可以用于调整大小和定位,例如负填充,这可能导致mpadded的内容与相邻内容的呈现重叠。 语法 (Syntax) 以下是使用此标记的简单语法 - <mpadded> expression </mpadded> 参数 (Parameters) 以下是此标记的所有参数的说明 - expression - 推断多个孩子的分娩。 属性 (Attributes)