2017-11-01 5 views
1

には適用できません。FirebaseからRecyclerviewにデータを取得しようとしています。私はすでに他のステップを実装していますが、アダプター(FirebaseRecyclerAdapter)を実装している最中にエラーが発生します。FirebaseRecyclerViewのFireBaseRecyclerViewは、(引数)

マイ・フラグメント

public class Journal extends Fragment { 

RecyclerView recyclerView; 
DatabaseReference myref; 
@Override 
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.activity_journal,container,false); 
    myref= FirebaseDatabase.getInstance().getReference("/Journal"); 
    recyclerView = (RecyclerView) v.findViewById(R.id.journal_rv); 
    recyclerView.setHasFixedSize(true); 
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); 
    FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
      JournalEntry.class, 
      R.layout.journal_list_item, 
      JournalHolder.class, 
      myref) { 
     @Override 
     protected void onBindViewHolder(JournalHolder holder, int position, JournalEntry model) { 
      holder.setTitle(model.getEvent_title()); 
      holder.setContent(model.getEvent_content()); 
      holder.setSchool(model.getSchool_name()); 
      holder.setDate(model.getDate()); 
      holder.setStudents(model.getNumber_of_students()); 
      holder.setSchoolIv(model.getImg_url()); 
     } 

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

return v; 
} 
public static class JournalHolder extends RecyclerView.ViewHolder{ 
    TextView Jtitle , Jcontent,Jschool,Jstudents,jdate; 
    ImageView schoolIV; 
    public JournalHolder(View itemView) { 
     super(itemView); 
     Jtitle =(TextView)itemView.findViewById(R.id.journal_title); 
     Jcontent =(TextView)itemView.findViewById(R.id.event_content); 
     Jschool =(TextView)itemView.findViewById(R.id.journal_school); 
     Jstudents =(TextView)itemView.findViewById(R.id.journal_students); 
     jdate = (TextView)itemView.findViewById(R.id.journal_dates) ; 
     schoolIV = (ImageView)itemView.findViewById(R.id.journal_image); 





    } 

    public void setTitle(String title) { 
     Jtitle.setText(title); 
    } 

    public void setContent(String content) { 
     Jcontent.setText(content); 
    } 

    public void setSchool(String school) { 
     Jschool.setText(school); 
    } 

    public void setDate(String date) { 
     jdate.setText(date); 
    } 

    public void setStudents(String students) { 
     Jstudents.setText(students); 
    } 

    public void setSchoolIv(String schoolIv) { 
     Picasso.with(itemView.getContext()) 
       .load(schoolIv) 
       .into(schoolIV); 
    } 
} 
} 

これは、私を助けてくださいエラー

FireBaseRecyclerView in FirebaseRecyclerView can not be applied to : 
JournalEntry.class (java...consti.last.database.JournalEntry>) 

R.layout.journal_list_item (int) 
BlogViewHolder.class (java...consti.last.Journal.BlogViewHolder>) 
myref (com...firebase.database.DatabaseReference) 

として示されているものです。私はすべての方法を試しましたが、何も動作しません。 アドバイスがありましたら...事前にありがとうございます。

PS:私が使用している断片アクティビティ宣言ライト下 That error is shown here

+0

あなたはbuild.gradleのコンパイルに書いたcom.firebaseui 'コンパイル':firebase-UI-データベースを: xxx '? // by x x最新のバージョン –

+0

をエラーにしていますが、blogviewholderと言っていますが、パラメータとしてジャーナルホルダーがあります –

+0

私はすでにblogViewholderに変更したエラーについてfirebase-uiデータベース11.4.2を使用しています。 – user8773560

答えて

1

: - onCreateView内部次いで

private FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter; 

():

adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
     JournalEntry.class, 
     R.layout.journal_list_item, 
     JournalHolder.class, 
     myref) { //be sure that these classes and parameters are correct.. 

return v;上述:

 recyclerView.setAdapter(adapter); 

利用代わりonBindViewHolderのこの方法:

@Override 
     protected void populateViewHolder(JournalHolder holder,JournalEntry model, int position) { 

あなたは、その適切な場所と右のレイアウトモデルクラスJournalEntry.classとホルダークラスJournalHolder.classで、そのすべての正しい方法を持っていることを確認してください。

+0

作品はありませんか?私もこれを試したが、それは動作していませんhttp://5ncode.blogspot.com.ar/2017/03/example-of-firebase-recylerview.html?m=1 – user8773560

+0

新しいエラーはクラス '匿名クラスの派生ですfrom FirebaseREcyclerAdaper 'は抽象メソッドとして宣言されなければならず、' Adapter 'の' oncreateViewHolder(ViewGroup、int) '抽象メソッドを実装しなければなりません。私はそのメソッドを実装するとき、私は同じコードを背後にあります。 – user8773560

+0

@ user8773560あなたは宣言を 'public class Journal extends Fragment {'? –

0

は私が最終的にここに解決策を見つけた:

0

Firebase RecyclerViewが、私は同じ問題を抱えていました。 このバージョンでFirebaseResycleViewは、次のようにします。

Query query = FirebaseDatabase.getInstance() 
      .getReference(); // you can add child as .child("child_name"); 


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

    FirebaseRecyclerAdapter<JournalEntry, JournalHolder> adapter = new FirebaseRecyclerAdapter<JournalEntry, JournalHolder>(
     options) { 
    @Override 
    protected void onBindViewHolder(JournalHolder holder, int position, JournalEntry model) { 
     holder.setTitle(model.getEvent_title()); 
     holder.setContent(model.getEvent_content()); 
     holder.setSchool(model.getSchool_name()); 
     holder.setDate(model.getDate()); 
     holder.setStudents(model.getNumber_of_students()); 
     holder.setSchoolIv(model.getImg_url()); 
    } 

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

そして忘れてはいけないの後:

recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); 
    recyclerView.setAdapter(adapter); 
    adapter.startListening(); 
+0

私の質問に答えるためにДмитрийПоляковに感謝します。これは非常に面白いです。しかし、私はそのコードをどこに置くべきかわかりません。もっと説明できますか? – user8773560