-1

I wrote this code

ref.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            TableRow tbrow = new TableRow(this);
..... 

I get the following error in the last line :

TableRow(android.content.Context) in TableRow cannot be applied to (anonymous com.google.firebase.database.valueEventListener).

I don't really get what is a context so what should I put as a parameter in TableRow ?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
kk123456
  • 23
  • 5
  • "this" in your code revers to the onDataChanged event, not to the context of your activity. create a context variable and inside your activities onCreate() method do context = this; Now inside your onDataChaged method of the TableRow, use "context" instead of "this" – Davi Jan 11 '19 at 23:24

1 Answers1

0

what should I put as a parameter in TableRow ?

Inside anonymous class, you can't use this as its a reference to anonymous class and required parameter is Activity's reference. change this with actityName.this.

Ali Ahsan
  • 985
  • 11
  • 16