我正在使用FirebaseUI的FirebaseRecyclerAdapter as described in 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();
}
我的POJO
String name;
public Chat() {
}
public Chat(String name) {
this.name = name;
}
public String getName() {
return name;
}
我ViewHolder
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);
}
}
請提供錯誤和鏈接到你正在使用的github類。您還可能想要[編輯]您的問題以顯示[mcve] –
@ cricket_007以下是鏈接(https://github.com/firebase/FirebaseUI-Android/blob/master/app/src/main/java/ com/firebase/uidemo/ChatActivity.java) –
如果Android Studio無法找到'FirebaseRecyclerAdapter'類,那麼您將缺少導入'import com.firebase.ui.database.FirebaseRecyclerAdapter;'或此依賴關係'compile'com .firebaseui:火力-UI-數據庫:0.4.0''。 –