0
我在活動中創建了一個選項卡視圖。現在我想顯示要從Firebase檢索的每個標籤內的列表項。是否有任何方式在Tab視圖中實現FirebaseListAdapter?
我可以檢索並顯示活動內的數據。但我不知道如何在片段內使用FirebaseListAdapter
。 FirebaseListAdapter
需要第一個參數作爲Activity
,但我如何將片段作爲活動傳遞?
childRef = databaseReference.child(str);
FirebaseListAdapter<Leave> firebaseListAdapter = new FirebaseListAdapter<Leave>(
this,
Leave.class,
R.layout.leavelistview,
childRef
) {
@Override
protected void populateView(View v, Leave model, int position) {
((TextView)v.findViewById(R.id.lv_staffname)).setText(model.getName());
((TextView)v.findViewById(R.id.lv_type)).setText(model.getType());
((TextView)v.findViewById(R.id.lv_duration)).setText(model.getDuration());
}
};
listView.setAdapter(firebaseListAdapter);
這是我在活動中使用的代碼。但是在一個片段中實現這個會給我一個錯誤,因爲我們不能通過this
來得到一個片段。
它仍然給我錯誤說期望的參數是'android.app.activity' –
'getActivity()嘗試使用' –
的錯誤消失。 –