Error reading Firebase data

Asked

Viewed 173 times

0

I try to read the data from firebase and put in the view Recycler, however is giving this error.

Error:(77, 73) error: constructor Firebaserecycleradapter in class Firebaserecycleradapter cannot be Applied to Given types; required: Firebaserecycleroptions found: Class,int,Class,Databasereference Reason: actual and formal argument lists differ in length Where T,VH are type-variables: T extends Object declared in class Firebaserecycleradapter VH extends Viewholder declared in class Firebaserecycleradapter Error:(80, 52) error: pm.pe.Gov.br.listatelefonica.fragments.Tab1fragment$1> is not Abstract and does not override Abstract method onBindViewHolder(Itemviewholder,int,Phonefixed) in Firebaserecycleradapter Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the Compiler error output for Details.

The error is in this line that is in the method to load Elephones(){} that is in the Fragment class

FirebaseRecyclerAdapter<TelefoneFixo, ItemViewHolder> adapter = new 
FirebaseRecyclerAdapter<TelefoneFixo, ItemViewHolder>(

My Adapter

public class AdapterFixo extends RecyclerView.Adapter<ItemViewHolder> {

private List<TelefoneFixo> mTelefoneFixo;

public AdapterFixo(List<TelefoneFixo> mTelefoneFixo) {
    this.mTelefoneFixo = mTelefoneFixo;
}

@Override
public ItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
    View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_row_fixo, viewGroup, false);
    return new ItemViewHolder(view);
}

@Override
public void onBindViewHolder(ItemViewHolder itemViewHolder, int position) {
    final TelefoneFixo model = mTelefoneFixo.get(position);
    itemViewHolder.bind(model);
}


@Override
public int getItemCount() {
    return mTelefoneFixo.size();
}

public void setFilter(List<TelefoneFixo> countryModels) {
    mTelefoneFixo = new ArrayList<>();
    mTelefoneFixo.addAll(countryModels);
    notifyDataSetChanged();
}
}

Fragment

public class Tab1Fragment extends Fragment implements SearchView.OnQueryTextListener {
private static final String TAG = "Tab1Fragment";
private RecyclerView recyclerview;
private List<TelefoneFixo> mTelfoneFixo;
private AdapterFixo adapterFixo;
FirebaseDatabase database;
DatabaseReference organizacao;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.tab1_fragment,container,false);
    recyclerview = (RecyclerView) view.findViewById(R.id.recyclerview);

   LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerview.setLayoutManager(layoutManager);
    recyclerview.setHasFixedSize(true);
    recyclerview.addItemDecoration(new DividerItemDecoration(getContext(), android.support.v7.widget.DividerItemDecoration.VERTICAL, 36));
    return view;
   // setHasOptionsMenu(true);


}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    setHasOptionsMenu(true);

 // mTelfoneFixo = getAllItemList();



    adapterFixo = new AdapterFixo(mTelfoneFixo);
    recyclerview.setAdapter(adapterFixo);

    database = FirebaseDatabase.getInstance();
    organizacao = database.getReference("Organização");
}

private void carregarTelefone() {

    FirebaseRecyclerAdapter<TelefoneFixo, ItemViewHolder> adapter = new FirebaseRecyclerAdapter<TelefoneFixo, ItemViewHolder>(
            TelefoneFixo.class,
            R.layout.list_row_fixo,
            ItemViewHolder.class, organizacao) {
        protected void populateViewHolder(ItemViewHolder itenViewHolder, TelefoneFixo model, int position) {
            itenViewHolder.nomeOrganizacao.setText(model.getNomeOrganizacao());
            itenViewHolder.nomeSecao.setText(model.getSiglaSecao());
            itenViewHolder.siglaOrganizacao.setText(model.getNomeOrganizacao());
        }
    };
    recyclerview.setAdapter(adapterFixo);

}

Viewholder

    public class ItemViewHolder extends RecyclerView.ViewHolder  {

    public TextView nomeOrganizacao;
    public TextView siglaOrganizacao;
    public TextView nomeSecao;


      public ItemViewHolder(View itemView) {super(itemView);
        siglaOrganizacao = (TextView) 
      itemView.findViewById(R.id.sigla_organizacao);
        nomeOrganizacao = (TextView) 
      itemView.findViewById(R.id.nome_organizacao);
        nomeSecao = (TextView) itemView.findViewById(R.id.nome_secao);

      }

    public void bind(TelefoneFixo telefoneFixoModel) {
        nomeOrganizacao.setText(telefoneFixoModel.getNomeOrganizacao());
        siglaOrganizacao.setText(telefoneFixoModel.getSiglaOrganizacao());
        nomeSecao.setText(telefoneFixoModel.getNomeSecao());

    }

}
  • Avoid posting pictures of the error. If possible copy and paste the log in the question. This way you will help those who check the error.

  • I added the error

1 answer

0

That’s because they changed the constructor of FirebaseRecyclerAdapter. Now you have to pass one FirebaseRecyclerOptions to the constructor. So:

FirebaseRecyclerOptions<TelefoneFixo> opcoes =
                new FirebaseRecyclerOptions.Builder<TelefoneFixo>()
                        .setQuery(organizacao, TelefoneFixo.class)
                        .build();

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<TelefoneFixo, ItemViewHolder>(opcoes) {
    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_row_fixo, parent, false);
        return new ItemViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(ItemViewHolder holder, int position, TelefoneFixo model) {
        holder.nomeOrganizacao.setText(model.getNomeOrganizacao());
        holder.nomeSecao.setText(model.getSiglaSecao());
        holder.siglaOrganizacao.setText(model.getNomeOrganizacao());
    }
};

Browser other questions tagged

You are not signed in. Login or sign up in order to post.