在我的活动中,在 onCreate()里面,我有这个:
std::queue<unsigned> q;
q.push(array[0]);
while (!q.empty())
{
unsigned index = q.front();
q.pop();
if(index >= someval){
index = index - someval;
q.push(array[index]);
}
else{
//do something
}
}
}
现在,我希望用Parishioner类型的对象填充我的RecyclerView,我已经定义了这个类:
final FirebaseRecyclerAdapter<String,MessageViewHolder> adapter = new FirebaseRecyclerAdapter<String, MessageViewHolder>(
String.class,
android.R.layout.two_line_list_item,
MessageViewHolder.class,
databaseReferenceCurrentUser
) {
@Override
protected void populateViewHolder(MessageViewHolder viewHolder, String model, int position) {
viewHolder.mText.setText(model);
}
};
mRecyclerView.setAdapter(adapter);
public static class MessageViewHolder extends RecyclerView.ViewHolder {
TextView mText;
public MessageViewHolder(View v){
super(v);
mText = (TextView) v.findViewById(android.R.id.text1);
}
}
在我的public class Parishioner {
private String parishionerName;
private String phoneNumber;
public Parishioner(String parishionerName, String phoneNumber) {
this.parishionerName = parishionerName;
this.phoneNumber = phoneNumber;
}
public Parishioner (){
}
public String getParishionerName() {
return parishionerName;
}
public void setParishionerName(String parishionerName) {
this.parishionerName = parishionerName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
中添加新的教区居民时,我使用
DB
我该怎么做?
答案 0 :(得分:1)
您需要将模型类String更改为Parishioner。
final FirebaseRecyclerAdapter<Parishioner, MessageViewHolder> adapter =
new FirebaseRecyclerAdapter<Parishioner, MessageViewHolder>(
Parishioner.class,
android.R.layout.two_line_list_item,
MessageViewHolder.class,
databaseReferenceCurrentUser) {
@Override
protected void populateViewHolder(MessageViewHolder viewHolder, Parishioner model, int position) {
viewHolder.mName.setText(model.getParishionerName());
viewHolder.mPhone.setText(model.getPhoneNumber());
}
};
mRecyclerView.setAdapter(adapter);
public static class MessageViewHolder extends RecyclerView.ViewHolder {
TextView mName;
TextView mPhone;
public MessageViewHolder(View v){
super(v);
mName= (TextView) v.findViewById(android.R.id.text1);
mPhone= (TextView) v.findViewById(android.R.id.text2);
}
}