我正在制作墙纸应用程序,并且试图在代表类别的墙纸上使用类别文本制作类别部分(例如,文字-自然,图片-森林)。问题是,当我播放该应用程序时,什么都没有显示,但是也没有错误,一切都应该正常工作,但事实并非如此。
Firebase规则都已设置。
我已授权该应用访问互联网。
依赖项:
dependencies {
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.firebaseui:firebase-ui-database:3.+'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.5'
}
类别片段类别:
public class CategoryFragment extends Fragment {
//Firebase
FirebaseDatabase database;
DatabaseReference categoryBackground;
//FirebaseUI adapteris
FirebaseRecyclerOptions<CategoryItem> options;
FirebaseRecyclerAdapter<CategoryItem, CategoryViewHolder> adapter;
//view
RecyclerView recyclerView;
private static CategoryFragment INSTANCE = null;
public CategoryFragment() {
// Required empty public constructor
database = FirebaseDatabase.getInstance();
categoryBackground = database.getReference(Common.STR_CATEGORY_BACKGROUND);
options = new FirebaseRecyclerOptions.Builder<CategoryItem>()
.setQuery(categoryBackground,CategoryItem.class)
.build();
adapter = new FirebaseRecyclerAdapter<CategoryItem, CategoryViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull final CategoryViewHolder holder, int position, @NonNull final CategoryItem model) {
Picasso.get()
.load(model.getImageLink())
.networkPolicy(NetworkPolicy.OFFLINE)
.into(holder.background_image, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
//Bandyti dar karta online jeigu nepavyksta
Picasso.get()
.load(model.getImageLink())
.error(R.drawable.ic_error_black_24dp)
.into(holder.background_image, new Callback() {
@Override
public void onSuccess() {
}
@Override
public void onError(Exception e) {
Log.e("ERROR_", "Couldn't fetch image");
}
});
}
});
holder.category_name.setText(model.getName());
holder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position) {
}
});
}
@Override
public CategoryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.layout_category_item, parent, false);
return new CategoryViewHolder(itemView);
}
};
}
public static CategoryFragment getInstance()
{
if(INSTANCE == null)
INSTANCE = new CategoryFragment();
return INSTANCE;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_category, container, false);
recyclerView = (RecyclerView)view.findViewById(R.id.recycler_category);
recyclerView.setHasFixedSize(true);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(),2);
recyclerView.setLayoutManager((gridLayoutManager));
setCategory();
return view;
}
private void setCategory() {
adapter.startListening();
recyclerView.setAdapter(adapter);
}
@Override
public void onStart() {
super.onStart();
if(adapter != null)
adapter.startListening();
}
@Override
public void onStop() {
if(adapter != null)
adapter.stopListening();
super.onStop();
}
@Override
public void onResume() {
super.onResume();
if(adapter != null)
adapter.startListening();
}
}
答案 0 :(得分:0)
找到了一个解决方案,我已经花了几个小时没注意到字符串中的拼写错误。杀了我。