嗨,我想用FirebaseAdaper填充Listview。数据正确填充,但是我在顶部看到一些空列。所有记录均从第三列写入。我想我从Firebase控制台实时数据库中手动删除了两条记录后开始看到这种情况。第二个问题是我也试图使用“ position”变量显示记录总数,但是它不起作用。这是我的代码:
ListView lv;
static int totalRecords;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
totalRecords = 0;
final FirebaseListAdapter <Profile>adapter;
v = findViewById(R.id.listview);
lv.setAdapter(null);
String sPath = "/Customer/" ;
sPath = sPath.replaceAll("\\s", "");
if( database != null) {
DatabaseReference myRef = database.getReference(sPath);
Query query = myRef.orderByChild("/sTimeServiced/");
if (query != null) {
totalRecords = 0;
FirebaseListOptions<Profile> options = new FirebaseListOptions.Builder<Profile>()
.setQuery(query, Profile.class)
.setLayout(android.R.layout.simple_selectable_list_item)
.setLifecycleOwner(this)
.build();
adapter = new FirebaseListAdapter<Profile>(options){
@Override
protected void populateView(View view, Profile p, int position) {
// totalRecords = totalRecords + 1;
TextView tv = findViewById(R.id.Count);
tv.setText(Integer.toString(position));
((TextView) view.findViewById(android.R.id.text1)).setText(p.sFN + " " + p.sLN + " (" + p.sTelephone + ")");
}
};
lv.setAdapter(adapter);
lv.setStackFromBottom(true);