Error reading data from Firebase

0

I'm trying to read the data from the firebase and put it in the recycler view, but it's giving this error.

  

Error: (77, 73) error: FirebaseRecyclerAdapter constructor in class   FirebaseRecyclerAdapter can not 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, Fixed Phone) 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 loadTelephones () {} 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());

    }

}
    
asked by anonymous 09.01.2018 / 11:59

1 answer

0

That's because they changed the FirebaseRecyclerAdapter constructor. You now have to pass 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());
    }
};
    
13.01.2018 / 14:36