github で説明されているように、 FirebaseUI の FirebaseRecyclerAdapterを使用しています。
しかし、エラーが発生しています (コンストラクターを解決できませんFirebaseRecyclerAdapter
)。可能な限りすべてを試しましたが、それでも同じエラーが発生します。
ここに私の活動があります
Firebase ref = new Firebase("https://myapp.firebaseio.com/shoplist");
RecyclerView recyclerView;
String enteredShopName;
private FirebaseRecyclerAdapter<Chat, ChatHolder> mRecyclerViewAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
createDialog();
}
});
}
@Override
protected void onStart() {
super.onStart();
attachRecyclerViewAdapter();
}
private void attachRecyclerViewAdapter() {
mRecyclerViewAdapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(
Chat.class, R.layout.message, ChatHolder.class, ref) {
@Override
public void populateViewHolder(ChatHolder chatView, Chat chat, int position) {
chatView.setName(chat.getName());
}
};
}
});
mRecyclerViewAdapter.setAdapter(mRecyclerViewAdapter);
}
private void createDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.addshop_dialog, null);
dialogBuilder.setView(dialogView);
final EditText randeephooda = (EditText) dialogView.findViewById(R.id.et_shopName);
enteredShopName = randeephooda.getText().toString();
dialogBuilder.setTitle("Add Shop");
dialogBuilder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//do something with edt.getText().toString();
Chat chat = new Chat(enteredShopName);
ref.push().setValue(chat);
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//pass
}
});
AlertDialog b = dialogBuilder.create();
b.show();
}
私のポジョ
String name;
public Chat() {
}
public Chat(String name) {
this.name = name;
}
public String getName() {
return name;
}
私のビューホルダー
public ChatHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setName(String name) {
TextView field = (TextView) mView.findViewById(R.id.shoprecyclerview_textView);
field.setText(name);
}
}