如何在RecyclerViewAdapter中获取列表?

时间:2017-02-06 14:22:44

标签: android firebase firebase-realtime-database

我花了很多时间来确定我的RecyclerView适配器出了什么问题。不断获取错误无法将java.util.ArrayList类型的对象转换为类型... Objectarraylist。

FirebaseRecyclerAdapter adapter=new FirebaseRecyclerAdapter<Objectarraylist,FragMessageAdapter>    (Objectarraylist.class,R.layout.cardview,
            FragMessageAdapter.class,databaseReference) {
        @Override
        protected void populateViewHolder(FragMessageAdapter viewHolder,  Objectarraylist model, int position) {

        }}

Objectarraylist类

public class Objectarraylist {
    public Objectarraylist(){}
    ArrayList<Following> arrayList;

    public ArrayList<Following> getArrayList() {
        return arrayList;
    }

    public void setArrayList(ArrayList<Following> arrayList) {
        this.arrayList = arrayList;
    }

    public Objectarraylist(ArrayList<Following> arrayList){
        this.arrayList=arrayList;
    }
}

课后

public class Following  {
    public ArrayList<String> coursename;
    public ArrayList<String> introtutor;
    public ArrayList<String> subject;

    public Following(){}

    public Following(ArrayList<String> name,ArrayList<String> into,ArrayList<String> sub){
        this.coursename=name;
        this.introtutor=into;
        this.subject=sub;
    }

    public ArrayList<String> getCoursename() {
        return coursename;
    }

    public void setCoursename(ArrayList<String> coursename) {
        this.coursename = coursename;
    }

    public ArrayList<String> getIntrotutor() {
        return introtutor;
    }

    public void setIntrotutor(ArrayList<String> introtutor) {
        this.introtutor = introtutor;
    }

    public ArrayList<String> getSubject() {
        return subject;
    }

    public void setSubject(ArrayList<String> subject) {``
        this.subject = subject;
    }
}

我试图将arraylist更改为字符串仍然得到相同的错误。 我不知道它是如何运作的。这浪费了我很多时间。

我想要检索包含3个子列表

的firebase数据
public class FragMessageAdapter extends RecyclerView.ViewHolder {
    ImageView image;
    TextView detail,name;

    private static final String LOG_TAG=FragMessageAdapter.class.getSimpleName();

    View newview;
    Context context;
    public FragMessageAdapter(View itemView) {
        super(itemView);

        newview=itemView;
        context=itemView.getContext();
    }

     public void bindmessagedata(Objectarraylist objectarraylist, int position){        
    }

}

错误:

FATAL EXCEPTION: main
  Process: com.example.vaibhav.upworkfirstproject, PID: 1813
  com.google.firebase.database.DatabaseException: Can't convert object of type java.util.ArrayList to type com.example.vaibhav.upworkfirstproject.Related_to_card_data.Objectarraylist
      at com.google.android.gms.internal.zzbqi.zze(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
      at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
      at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
      at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:152)
      at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:141)
      at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:184)
      at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6279)
      at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6312)
      at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5258)
      at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5521)
      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5363)
      at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5359)
      at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2141)
      at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1525)
      at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1488)
      at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:585)
      at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3506)
      at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3254)
      at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1623)
      at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:331)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:860)
      at android.view.Choreographer.doCallbacks(Choreographer.java:672)
      at android.view.Choreographer.doFrame(Choreographer.java:605)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:148)
      at android.app.ActivityThread.main(ActivityThread.java:5441)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)

Json我想要检索

 {
"follow" : {
"coursename" : [ "vaibhav" ],
"introtutor" : [ "Hi i am vaibhav" ],
"subject" : [ "Computer Science" ]
}
}

0 个答案:

没有答案