在firebase

时间:2018-03-31 03:54:03

标签: arraylist firebase-realtime-database firebase-authentication recycler-adapter

enter link description here

Adapter class:

这是我项目的Adapter类。

public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHolder> {

    private Context context;
    private ArrayList<Product> mProduct;

    public ProductAdapter(Context con, ArrayList<Product> list) {
        this.context = con;
        this.mProduct = list;
    }
    @Override
    public ProductAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ProductAdapter.MyViewHolder holder, int position) {

        Product contact = mProduct.get(position);
        holder.name.setText(mProduct.get(position).getName());
        holder.pass.setText(mProduct.get(position).getPass());
        holder.ward.setText(mProduct.get(position).getWard());

    }

这是我的 ValueEvent侦听器

ValueEvent Listener:


        FirebaseDatabase database = FirebaseDatabase.getInstance();
        final DatabaseReference ref = database.getReference();



        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();



                for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                    Product item = snapshot.getValue(Product.class);
                    mProductList.add(item);
                }
                productAdapter.notifyDataSetChanged();


            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }

        });









  Description:



Objective of this coding: Real time viewing of added members based on the Region & sub-region chosen under a state.

Attached image has the key of each member, their attributes added.

Based on this, the expectation is to list the members, however, the code does not return any error, except blank screen.

我尝试在Recyclerview中检索所有“用户”详细信息,但空白屏幕显示没有任何错误。

I trying for past days. Please help me.

此编码的目标:基于Region&amp ;;实时查看添加的成员。在一个州选择的次区域。

Attached image has the key of each member, their attributes added.

Based on this, the expectation is to list the members, however, the code does not return any error, except blank screen.

我尝试在Recyclerview中检索所有“用户”详细信息,但空白屏幕显示没有任何错误。

I trying for past 4 days. Please help me.

1 个答案:

答案 0 :(得分:0)

现在我解决了这个问题的朋友。 我的错误在&#34;布局xml文件&#34;,在线性布局中,我提到&#34; matchparent&#34;对于高度,所以线性布局应占据xml中的所有空间。 我改变了#34; matchparent&#34; to&#34; warpcontent&#34;我会检索所有数据....

        Thanks Friends....