gpt4 book ai didi

java - 在我的 FirebaseRecyclerAdapter 方法中,我看不到 populateviewholder 方法未实现

转载 作者:行者123 更新时间:2023-12-01 23:51:55 26 4
gpt4 key购买 nike

我想从 firebase 检索数据。当我添加 FirebaseRecyclerAdapter 方法时 populateviewholder 方法没有实现而不是这个。另外两个onCreateViewHoldermethod onBind方法正在实现为什么会发生这种情况

import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.expensemanager.model.Data;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;


/**
* A simple {@link Fragment} subclass.
*/
public class IncomeFragment extends Fragment {


public IncomeFragment() {
// Required empty public constructor
}

//firebase database
private FirebaseDatabase fireDatabase;
private FirebaseAuth firebaseAuth;
private DatabaseReference mIncomeDatabase, mExpenseDatabase;
private RecyclerView recycleView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView = inflater.inflate(R.layout.fragment_income, container, false);
firebaseAuth = FirebaseAuth.getInstance();
FirebaseUser fireUser = firebaseAuth.getCurrentUser();
String uid = fireUser.getUid();
mIncomeDatabase = FirebaseDatabase.getInstance().getReference().child("Income Data 1").child(uid);

recycleView = myView.findViewById(R.id.recycle_income);
LinearLayoutManager linManager = new LinearLayoutManager(getActivity());
linManager.setReverseLayout(true);
linManager.setStackFromEnd(true);
recycleView.setHasFixedSize(true);
recycleView.setLayoutManager(linManager);
return myView;
}

@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Data,myViewHolder> adapter = new FirebaseRecyclerAdapter<Data, myViewHolder>(
Data.class, R.layout.income_recycler_data, myViewHolder.class, mIncomeDatabase
) {
@Override
protected void onBindViewHolder(@NonNull myViewHolder viewHolder, int i, @NonNull Data data) {

}

@NonNull
@Override
public myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
};
}

public static class myViewHolder extends RecyclerView.ViewHolder{
View mView;
public myViewHolder(@NonNull View itemView) {
super(itemView);
mView = itemView;
}
private void setType(String type){
TextView mType = itemView.findViewById(R.id.type_text_income);
mType.setText(type);
}
private void setNote(String note){
TextView mNote = itemView.findViewById(R.id.note_text_income);
mNote.setText(note);
}
private void setDate(String date){
TextView mDate = itemView.findViewById(R.id.date_text_income);
mDate.setText(date);
}
private void setAmount(int amount){
TextView mAmount = itemView.findViewById(R.id.amount_text_income);
String retriveAmount = String.valueOf(amount);
mAmount.setText(retriveAmount);

}

}


}

当我手动添加 populateviewholder 方法时,android studio 给我一个错误。

最佳答案

populateviewholder 已删除。现在您需要执行以下操作:

首先使用 FirebaseRecyclerOptions 配置适配器

 FirebaseRecyclerOptions<Chat> options =
new FirebaseRecyclerOptions.Builder<Data>()
.setQuery(query, Data.class)
.build();

接下来创建 FirebaseRecyclerAdapter:

FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Data, myViewHolder>(options) {
@Override
public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Create a new instance of the ViewHolder, in this case we are using a custom
// layout called R.layout.message for each item
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.message, parent, false);

return new myViewHolder(view);
}

@Override
protected void onBindViewHolder(myViewHolderholder, int position, Data model) {
// Bind the Data object to the myViewHolder
// ...
}
};

查看此处了解更多详细信息:

https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md

关于java - 在我的 FirebaseRecyclerAdapter 方法中,我看不到 populateviewholder 方法未实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58217168/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com