Привет. Я пытаюсь заполнить Listview с помощью FirebaseAdaper.Данные заполнены правильно, но я вижу несколько пустых столбцов в верхней части.все записи пишутся из третьего столбца.Думаю, я начал это видеть после того, как вручную удалил две записи из базы данных консоли 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);