Reputation: 13
I am trying to retrieve a list of items from Firebase
and after all the data is retrieved, I want to inflate the data in listView
using an adaptor. Here is the code I am using:
vehicleReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
for (DataSnapshot data : dataSnapshot.getChildren()){
ServiceHistoryDataModel serviceHistoryData = data.getValue(ServiceHistoryDataModel.class);
serviceHistoryDataList.add(serviceHistoryData);
}
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter (this,serviceHistoryDataList,getLayoutInflater());
listView.setAdapter(adapter);
}else
Toast.makeText(ServiceHistoryActivity.this, "No service history available !", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
(please refer the screenshot)
I am getting an error :-
"ServiceHistoryListAdpter() in ServiceHistoryListAdapter cannot be applied:..."
For the line:
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter (this,serviceHistoryDataList,getLayoutInflater());
Could you please let me know how can I solve this?
Upvotes: 0
Views: 389
Reputation: 1171
You want to access the instance of enclosing class from the anonymous class. The syntax for which is EnclosingClassName.this
.
So change the line to:
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter(YourActivityName.this,serviceHistoryDataList,getLayoutInflater());
i.e. add YourActivityName.
before this
.
Upvotes: 4
Reputation:
Replace your code with this.
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter(ActivityName.this,serviceHistoryDataList,getLayoutInflater());
Upvotes: 1
Reputation: 131
Please replace
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter(this,serviceHistoryDataList,getLayoutInflater());
with
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter(YourActivityName.this,serviceHistoryDataList,getLayoutInflater());
Upvotes: 1
Reputation: 648
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter(YourActivityName.this,serviceHistoryDataList,getLayoutInflater());
Upvotes: 0
Reputation: 1795
Just pass parameter like "YourActivityName.this" your problem will be resolved. Check out code below for the same.
ServiceHistoryListAdapter adapter = new ServiceHistoryListAdapter(YourActivityName.this,serviceHistoryDataList,getLayoutInflater());
Upvotes: 1