我的 customAdapter 或 Activity.java 有什么问题? 运行 应用程序时,我的 ListView 不显示它的元素
What is wrong with my customAdapter or Activity.java? my ListView not showing it's element when running the app
我正在开发 RecyclerView 并使用 CustomAdapter,我的应用程序运行顺利,但我的 ListView 没有显示它的内容!我的代码有什么缺失或错误?
我尝试 return arraylist.size() 并输入 list.setHasFixedSize 但没有成功!
prospectowner_listview.java (Activity class)
public class prospectowner_listview extends AppCompatActivity {
RecyclerView list;
ArrayList <com.example.android.e7gzlykora.owner> ownerlist = new ArrayList <>();
private DatabaseReference mFirebaseDatabase;
private FirebaseDatabase mFirebaseInstance;
owner owner;
customAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prospectowner_listview);
list = findViewById(R.id.list);
LinearLayoutManager manager = new LinearLayoutManager(this);
list.setLayoutManager(manager);
list.setHasFixedSize(true);
manager.setOrientation(LinearLayoutManager.VERTICAL);
adapter = new customAdapter(prospectowner_listview.this,ownerlist);
mFirebaseInstance = FirebaseDatabase.getInstance();
mFirebaseDatabase = mFirebaseInstance.getReference("owners");
mFirebaseDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()){
owner o = data.getValue(owner.class);
ownerlist.add(o);
}
list.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) { }
});
}
}
CustomerAdapter.java
public class customAdapter extends RecyclerView.Adapter<customAdapter.MyViewHolder>{
private final ArrayList<owner> ownerlist;
private final Context mContext;
public customAdapter(Context c , ArrayList<owner> p) {
this.mContext = c;
this.ownerlist = new ArrayList <>();
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.prospectowners,parent,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
owner owner = ownerlist.get(position);
holder.name.setText(owner.getName());
holder.field.setText(owner.getFieldname());
holder.mobile.setText(owner.getMobile());
holder.address.setText(owner.getAddress());
holder.cost.setText(owner.getCost());
}
@Override
public int getItemCount() {
return ownerlist.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public TextView field;
public TextView mobile;
public TextView address;
public TextView cost;
public MyViewHolder(View itemView) {
super(itemView);
this.name = itemView.findViewById(R.id.name);
this.field = itemView.findViewById(R.id.fieldName);
this.mobile = itemView.findViewById(R.id.mobileowner);
this.address = itemView.findViewById(R.id.address);
this.cost = itemView.findViewById(R.id.cost);
}
}
}
Owner.java
public class owner extends ArrayList <owner> {
public String name;
public String mobile;
public String fieldname;
public String address;
public String cost;
public String zone1;
public String zone2;
private Class thisClass;
public owner(){}
public owner(String name, String mobile,String fieldname,String address, String cost, String zone1, String zone2) {
this.name = name;
this.mobile = mobile;
this.fieldname = fieldname;
this.address = address;
this.cost = cost;
this.zone1 = zone1;
this.zone2 = zone2;
}
public String getMobile() {
return mobile;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public void setName(String name) {
this.name = name;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public void setFieldname(String fieldname) {
this.fieldname = fieldname;
}
public void setAddress(String address) {
this.address = address;
}
public void setCost(String cost) {
this.cost = cost;
}
public void setZone1(String zone1) {
this.zone1 = zone1;
}
public void setZone2(String zone2) {
this.zone2 = zone2;
}
public void setThisClass(Class thisClass) {
this.thisClass = thisClass;
}
public String getFieldname() {
return fieldname;
}
public String getCost() {
return cost;
}
public String getZone1() {
return zone1;
}
public String getZone2() {
return zone2;
}
}
---------------- prospectowners.xml----------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<TextView
android:id="@+id/fieldName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@android:color/black"
android:textStyle="bold"
/>
<TextView
android:id="@+id/nameowner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/fieldName"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:text=""
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/mobileowner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/nameowner"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/mobileowner"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/address"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
/>
<Button
android:id="@+id/reserve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cost"
android:onClick="reserve"
android:layout_marginStart="230dp"
android:layout_marginLeft="270dp"
android:layout_marginTop="10dp"
android:text="E7gzly"
android:textSize="15dp" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
试试这个,
在你的activityclass改变
list.setAdapter(adapter)
至
list.setAdapter(new customAdapter(prospectowner_listview.this, ownerlist));
在您的适配器中创建新函数:
public void addData(List<Owner> owners){
this.ownerList = owners;
notifyOnDataSetChanged();
}
并在 onDataChange
中调用:
adapter.addData(owners);
我认为问题出在您的适配器上,请像下面这样更改您的适配器代码:
public class customAdapter extends RecyclerView.Adapter<customAdapter.MyViewHolder>{
private ArrayList<owner> ownerlist;
private Context mContext;
public customAdapter(Context c , ArrayList<owner> p) {
this.mContext = c;
this.ownerlist = p;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.prospectowners,parent,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
owner owner = ownerlist.get(position);
holder.name.setText(owner.getName());
holder.field.setText(owner.getFieldname());
holder.mobile.setText(owner.getMobile());
holder.address.setText(owner.getAddress());
holder.cost.setText(owner.getCost());
}
@Override
public int getItemCount() {
return ownerlist.size();
}
public void addData(ArrayList<owner> newData){
this.ownerlist.addAll(newData);
notifyOnDataSetChanged();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public TextView field;
public TextView mobile;
public TextView address;
public TextView cost;
public MyViewHolder(View itemView) {
super(itemView);
this.name = itemView.findViewById(R.id.name);
this.field = itemView.findViewById(R.id.fieldName);
this.mobile = itemView.findViewById(R.id.mobileowner);
this.address = itemView.findViewById(R.id.address);
this.cost = itemView.findViewById(R.id.cost);
}
}
}
然后像这样调用方法 addData
:
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()){
owner o = data.getValue(owner.class);
ownerlist.add(o);
}
list.setAdapter(adapter);
adapter.addData(ownerlist);
}
顺便说一句,实际上你可以在监听器之外设置适配器
UPDATE(本次更新将adapter值的位置设置为默认为空数据,触发listener时填充)
public class customAdapter extends RecyclerView.Adapter<customAdapter.MyViewHolder>{
private ArrayList<owner> ownerlist;
private Context mContext;
public customAdapter(Context c , ArrayList<owner> p) {
this.mContext = c;
this.ownerlist = new Arraylist<>();
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.prospectowners,parent,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
owner owner = ownerlist.get(position);
holder.name.setText(owner.getName());
holder.field.setText(owner.getFieldname());
holder.mobile.setText(owner.getMobile());
holder.address.setText(owner.getAddress());
holder.cost.setText(owner.getCost());
}
@Override
public int getItemCount() {
return ownerlist.size();
}
public void addData(ArrayList<owner> newData){
this.ownerlist.addAll(newData);
notifyOnDataSetChanged();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public TextView field;
public TextView mobile;
public TextView address;
public TextView cost;
public MyViewHolder(View itemView) {
super(itemView);
this.name = itemView.findViewById(R.id.name);
this.field = itemView.findViewById(R.id.fieldName);
this.mobile = itemView.findViewById(R.id.mobileowner);
this.address = itemView.findViewById(R.id.address);
this.cost = itemView.findViewById(R.id.cost);
}
}
}
public class prospectowner_listview extends AppCompatActivity {
RecyclerView list;
ArrayList <com.example.android.e7gzlykora.owner> ownerlist = new ArrayList <>();
private DatabaseReference mFirebaseDatabase;
private FirebaseDatabase mFirebaseInstance;
owner owner;
customAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prospectowner_listview);
list = findViewById(R.id.list);
LinearLayoutManager manager = new LinearLayoutManager(this);
list.setLayoutManager(manager);
list.setHasFixedSize(true);
manager.setOrientation(LinearLayoutManager.VERTICAL);
adapter = new customAdapter(prospectowner_listview.this,ownerlist);
list.setAdapter(adapter);
mFirebaseInstance = FirebaseDatabase.getInstance();
mFirebaseDatabase = mFirebaseInstance.getReference("owners");
mFirebaseDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()){
owner o = data.getValue(owner.class);
ownerlist.add(o);
}
adapter.addData(ownerlist);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) { }
});
}
}
数组列表始终为空,因为您将适配器构造函数初始化为新列表。请查看
我正在开发 RecyclerView 并使用 CustomAdapter,我的应用程序运行顺利,但我的 ListView 没有显示它的内容!我的代码有什么缺失或错误? 我尝试 return arraylist.size() 并输入 list.setHasFixedSize 但没有成功!
prospectowner_listview.java (Activity class)
public class prospectowner_listview extends AppCompatActivity {
RecyclerView list;
ArrayList <com.example.android.e7gzlykora.owner> ownerlist = new ArrayList <>();
private DatabaseReference mFirebaseDatabase;
private FirebaseDatabase mFirebaseInstance;
owner owner;
customAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prospectowner_listview);
list = findViewById(R.id.list);
LinearLayoutManager manager = new LinearLayoutManager(this);
list.setLayoutManager(manager);
list.setHasFixedSize(true);
manager.setOrientation(LinearLayoutManager.VERTICAL);
adapter = new customAdapter(prospectowner_listview.this,ownerlist);
mFirebaseInstance = FirebaseDatabase.getInstance();
mFirebaseDatabase = mFirebaseInstance.getReference("owners");
mFirebaseDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()){
owner o = data.getValue(owner.class);
ownerlist.add(o);
}
list.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) { }
});
}
}
CustomerAdapter.java
public class customAdapter extends RecyclerView.Adapter<customAdapter.MyViewHolder>{
private final ArrayList<owner> ownerlist;
private final Context mContext;
public customAdapter(Context c , ArrayList<owner> p) {
this.mContext = c;
this.ownerlist = new ArrayList <>();
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.prospectowners,parent,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
owner owner = ownerlist.get(position);
holder.name.setText(owner.getName());
holder.field.setText(owner.getFieldname());
holder.mobile.setText(owner.getMobile());
holder.address.setText(owner.getAddress());
holder.cost.setText(owner.getCost());
}
@Override
public int getItemCount() {
return ownerlist.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public TextView field;
public TextView mobile;
public TextView address;
public TextView cost;
public MyViewHolder(View itemView) {
super(itemView);
this.name = itemView.findViewById(R.id.name);
this.field = itemView.findViewById(R.id.fieldName);
this.mobile = itemView.findViewById(R.id.mobileowner);
this.address = itemView.findViewById(R.id.address);
this.cost = itemView.findViewById(R.id.cost);
}
}
}
Owner.java
public class owner extends ArrayList <owner> {
public String name;
public String mobile;
public String fieldname;
public String address;
public String cost;
public String zone1;
public String zone2;
private Class thisClass;
public owner(){}
public owner(String name, String mobile,String fieldname,String address, String cost, String zone1, String zone2) {
this.name = name;
this.mobile = mobile;
this.fieldname = fieldname;
this.address = address;
this.cost = cost;
this.zone1 = zone1;
this.zone2 = zone2;
}
public String getMobile() {
return mobile;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public void setName(String name) {
this.name = name;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public void setFieldname(String fieldname) {
this.fieldname = fieldname;
}
public void setAddress(String address) {
this.address = address;
}
public void setCost(String cost) {
this.cost = cost;
}
public void setZone1(String zone1) {
this.zone1 = zone1;
}
public void setZone2(String zone2) {
this.zone2 = zone2;
}
public void setThisClass(Class thisClass) {
this.thisClass = thisClass;
}
public String getFieldname() {
return fieldname;
}
public String getCost() {
return cost;
}
public String getZone1() {
return zone1;
}
public String getZone2() {
return zone2;
}
}
---------------- prospectowners.xml----------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<TextView
android:id="@+id/fieldName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@android:color/black"
android:textStyle="bold"
/>
<TextView
android:id="@+id/nameowner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/fieldName"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:text=""
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/mobileowner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/nameowner"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/mobileowner"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
/>
<TextView
android:id="@+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/address"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textColor="@android:color/black"
/>
<Button
android:id="@+id/reserve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/cost"
android:onClick="reserve"
android:layout_marginStart="230dp"
android:layout_marginLeft="270dp"
android:layout_marginTop="10dp"
android:text="E7gzly"
android:textSize="15dp" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
试试这个,
在你的activityclass改变
list.setAdapter(adapter)
至
list.setAdapter(new customAdapter(prospectowner_listview.this, ownerlist));
在您的适配器中创建新函数:
public void addData(List<Owner> owners){
this.ownerList = owners;
notifyOnDataSetChanged();
}
并在 onDataChange
中调用:
adapter.addData(owners);
我认为问题出在您的适配器上,请像下面这样更改您的适配器代码:
public class customAdapter extends RecyclerView.Adapter<customAdapter.MyViewHolder>{
private ArrayList<owner> ownerlist;
private Context mContext;
public customAdapter(Context c , ArrayList<owner> p) {
this.mContext = c;
this.ownerlist = p;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.prospectowners,parent,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
owner owner = ownerlist.get(position);
holder.name.setText(owner.getName());
holder.field.setText(owner.getFieldname());
holder.mobile.setText(owner.getMobile());
holder.address.setText(owner.getAddress());
holder.cost.setText(owner.getCost());
}
@Override
public int getItemCount() {
return ownerlist.size();
}
public void addData(ArrayList<owner> newData){
this.ownerlist.addAll(newData);
notifyOnDataSetChanged();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public TextView field;
public TextView mobile;
public TextView address;
public TextView cost;
public MyViewHolder(View itemView) {
super(itemView);
this.name = itemView.findViewById(R.id.name);
this.field = itemView.findViewById(R.id.fieldName);
this.mobile = itemView.findViewById(R.id.mobileowner);
this.address = itemView.findViewById(R.id.address);
this.cost = itemView.findViewById(R.id.cost);
}
}
}
然后像这样调用方法 addData
:
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()){
owner o = data.getValue(owner.class);
ownerlist.add(o);
}
list.setAdapter(adapter);
adapter.addData(ownerlist);
}
顺便说一句,实际上你可以在监听器之外设置适配器
UPDATE(本次更新将adapter值的位置设置为默认为空数据,触发listener时填充)
public class customAdapter extends RecyclerView.Adapter<customAdapter.MyViewHolder>{
private ArrayList<owner> ownerlist;
private Context mContext;
public customAdapter(Context c , ArrayList<owner> p) {
this.mContext = c;
this.ownerlist = new Arraylist<>();
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.prospectowners,parent,false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
owner owner = ownerlist.get(position);
holder.name.setText(owner.getName());
holder.field.setText(owner.getFieldname());
holder.mobile.setText(owner.getMobile());
holder.address.setText(owner.getAddress());
holder.cost.setText(owner.getCost());
}
@Override
public int getItemCount() {
return ownerlist.size();
}
public void addData(ArrayList<owner> newData){
this.ownerlist.addAll(newData);
notifyOnDataSetChanged();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public TextView field;
public TextView mobile;
public TextView address;
public TextView cost;
public MyViewHolder(View itemView) {
super(itemView);
this.name = itemView.findViewById(R.id.name);
this.field = itemView.findViewById(R.id.fieldName);
this.mobile = itemView.findViewById(R.id.mobileowner);
this.address = itemView.findViewById(R.id.address);
this.cost = itemView.findViewById(R.id.cost);
}
}
}
public class prospectowner_listview extends AppCompatActivity {
RecyclerView list;
ArrayList <com.example.android.e7gzlykora.owner> ownerlist = new ArrayList <>();
private DatabaseReference mFirebaseDatabase;
private FirebaseDatabase mFirebaseInstance;
owner owner;
customAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prospectowner_listview);
list = findViewById(R.id.list);
LinearLayoutManager manager = new LinearLayoutManager(this);
list.setLayoutManager(manager);
list.setHasFixedSize(true);
manager.setOrientation(LinearLayoutManager.VERTICAL);
adapter = new customAdapter(prospectowner_listview.this,ownerlist);
list.setAdapter(adapter);
mFirebaseInstance = FirebaseDatabase.getInstance();
mFirebaseDatabase = mFirebaseInstance.getReference("owners");
mFirebaseDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()){
owner o = data.getValue(owner.class);
ownerlist.add(o);
}
adapter.addData(ownerlist);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) { }
});
}
}
数组列表始终为空,因为您将适配器构造函数初始化为新列表。请查看