我无法在动态表格布局上显示Firebase数据库中的任何数据。
我希望在页面视图中创建它。我创建了一个在if条件为真时调用的函数。
我能否知道我在哪里做错了?
我已经为两个不同的引用声明了两个数据库侦听器。
final DatabaseReference priceLevel = placeRef.child("price_level/"+ estBudget+"/");
priceLevel.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
placeObj place = dataSnapshot.getValue(placeObj.class); //get value from firebase?
Log.d(TAG, "I am inside the find place to eat event listener."); //this log did not even appear in the console.
for (int i = 0; i <= Integer.valueOf(days); i++) {
TextView place_name = new TextView(getApplicationContext());
place_name.setText(place.getPlace_name());
place_name.setTextSize(20);
place_name.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 5f));
place_name.setTextColor(Color.BLACK);
Log.d(TAG, "Place name: " + place_name);
TextView place_type = new TextView(getApplicationContext());
place_type.setText("Description" + place.getPlace_type());
place_type.setTextSize(20);
place_type.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 5f));
place_type.setTextColor(Color.BLACK);
TextView price_range = new TextView(getApplicationContext());
price_range.setText("SGD$ " + place.getPrice_range());
price_range.setTextSize(20);
price_range.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 5f));
price_range.setTextColor(Color.BLACK);
TextView vegan_type = new TextView(getApplicationContext());
vegan_type.setText("Vegan friendly:" + place.getVegan_type());
vegan_type.setTextSize(20);
vegan_type.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 5f));
vegan_type.setTextColor(Color.BLACK);
TextView website = new TextView(getApplicationContext());
website.setText("Website: " + Html.fromHtml(place.getWebsite()));
website.setTextSize(20);
website.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT, 5f));
website.setTextColor(Color.BLACK);
TableRow row = new TableRow(getApplicationContext());
row.setGravity(Gravity.CENTER_HORIZONTAL);
row.addView(place_name);
row.addView(place_type);
row.addView(price_range);
row.addView(vegan_type);
row.addView(website);
tblLocation.addView(row);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
这是我收到的输出,禁止我输入onDataChange: