我想从火力点实时数据库显示图片。(带有加密图像(字符串))类似加密图像是“照片”
public class ItemObject {
private String title;
private String Photo;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPhoto() {
return Photo;
}
public void setPhoto(String photo){
this.Photo=photo;
}
public ItemObject(String title, String photo) {
this.title = title;
this.Photo=photo;
}
public ItemObject() {}
}
Recyclerview adpater MyAdapter.java
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.RecyclerViewHolders> {
private Context context;
private ArrayList<ItemObject> mItem;
private AdapterView.OnItemClickListener mListener = null;
public class RecyclerViewHolders extends RecyclerView.ViewHolder
implements View.OnCreateContextMenuListener {
TextView title;
ImageView imageView;
// private CardView cardView;
public RecyclerViewHolders(@NonNull View itemView) {
super(itemView);
this.title = itemView.findViewById(R.id.title_listitem);
this.imageView = itemView.findViewById(R.id.photo_listitem);
//
itemView.setOnCreateContextMenuListener(this);
}
private final MenuItem.OnMenuItemClickListener onEditMenu = new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case 1001:
mItem.remove(getAdapterPosition());
notifyItemRemoved(getAdapterPosition());
notifyItemRangeChanged(getAdapterPosition(), mItem.size());
break;
}
return true;
}
};
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
MenuItem Delete = menu.add(Menu.NONE,1001,1,"삭제");
Delete.setOnMenuItemClickListener(onEditMenu);
}
}
public MyAdapter(ArrayList<ItemObject> item){
this.context = context;
this.mItem = item;
}
@NonNull
@Override
public RecyclerViewHolders onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.listitem,viewGroup,false);
RecyclerViewHolders viewHolders=new RecyclerViewHolders(view);
return viewHolders;
}
@Override
public void onBindViewHolder(@NonNull RecyclerViewHolders holder, int position) {
/* Glide.with(context)
.load(mItem.get(position).getPhoto())
.into(holder.imageView);
*/
ItemObject itemObject = mItem.get(position);
String photo = itemObject.getPhoto();
holder.title.setTextSize(TypedValue.COMPLEX_UNIT_SP,10);
holder.title.setGravity(Gravity.CENTER);
holder.title.setText(itemObject.getTitle());
holder.imageView.setImageURI(Uri.parse(photo));
// Glide.with(this.context).load(mItem.get(position).getPhoto()).centerCrop().into(holder.imageView);
}
public void setmItem(ArrayList<ItemObject> mItem) {
this.mItem = mItem;
}
public void deleteItem(int position) {
mItem.remove(position);
notifyItemRemoved(position);
}
@Override
public int getItemCount() {
return mItem.size();
}
}
mRecyclerView = findViewById(R.id.recyclerview_main_list);
int numberOfColumns = 3;
GridLayoutManager mGridLayoutManager = new GridLayoutManager(getApplication(),numberOfColumns);
mRecyclerView.setLayoutManager(mGridLayoutManager);
mRecyclerView.setHasFixedSize(true);
reference = FirebaseDatabase.getInstance().getReference();
mItem = new ArrayList<>();
//clearAll();
loadPhoto();
DividerItemDecoration dividerItemDecoration=new DividerItemDecoration(mRecyclerView.getContext(),mGridLayoutManager.getOrientation());
mRecyclerView.addItemDecoration(dividerItemDecoration);
mRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(getApplicationContext(), mRecyclerView, new ClickListener() {
@Override
public void onClick(View view, int position) {
ItemObject itemObject = mItem.get(position);
Intent intent = new Intent(getApplicationContext(), DetailActivity.class);
intent.putExtra("title",itemObject.getTitle());
intent.putExtra("photo",itemObject.getPhoto());
startActivity(intent);
}
@Override
public void onLongClick(View view, int position) {
}
}));
函数loadPhoto()
private void loadPhoto() {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
String key = FirebaseDatabase.getInstance().getInstance().getReference("users")
.child(currentUser.getUid()).child("Object").getKey();
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("users")
.child(currentUser.getUid()).child("Object").child(key);
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
mRecyclerView = findViewById(R.id.recyclerview_main_list);
int numberOfColumns = 3;
GridLayoutManager mGridLayoutManager = new GridLayoutManager(getApplication(),numberOfColumns);
mRecyclerView.setLayoutManager(mGridLayoutManager);
mRecyclerView.setHasFixedSize(true);
ItemObject itemObject = new ItemObject();
//여기서 에러
String En1 = snapshot.child("photo").getValue().toString();
byte []En2 = En1.getBytes();
AESCoderAndriod aesCoderAndriod = new AESCoderAndriod();
try {
byte []Dn1 = aesCoderAndriod.decrypt(seed,En2);
Bitmap Dn2 = byteArrayToBitmap(Dn1);
Uri Dn3 = getImageUri(getApplicationContext(),Dn2);
itemObject.setPhoto(Dn3.toString());
itemObject.setTitle(snapshot.child("title").getValue().toString());
mItem.add(itemObject);
} catch (Exception e) {
e.printStackTrace();
}
// itemObject.setPhoto(snapshot.child("Photo").getValue().toString());
}
//myAdapter= new MyAdapter(getApplicationContext(),mItem);
// mRecyclerView.setAdapter(myAdapter);
myAdapter = new MyAdapter(mItem);
mRecyclerView.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
问题出在哪里?我连接adapter和recyclerview,并设置GridManager。
您应该首先设置您的适配器,从空的回收器视图开始,当数据加载时,您应该通知您的适配器有关更改。
mRecyclerView.setLayoutManager(mGridLayoutManager);
mRecyclerView.setHasFixedSize(true);
mItem = new ArrayList<>();
myAdapter = new MyAdapter(mItem);
mRecyclerView.setAdapter(myAdapter);
loadPhoto();
您的函数已经包含了notify data change方法。不需要在数据加载方法上设置新的布局管理器
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
ItemObject itemObject = new ItemObject();
//여기서 에러
String En1 = snapshot.child("photo").getValue().toString();
byte []En2 = En1.getBytes();
AESCoderAndriod aesCoderAndriod = new AESCoderAndriod();
try {
byte []Dn1 = aesCoderAndriod.decrypt(seed,En2);
Bitmap Dn2 = byteArrayToBitmap(Dn1);
Uri Dn3 = getImageUri(getApplicationContext(),Dn2);
itemObject.setPhoto(Dn3.toString());
itemObject.setTitle(snapshot.child("title").getValue().toString());
mItem.add(itemObject);
} catch (Exception e) {
e.printStackTrace();
}
// itemObject.setPhoto(snapshot.child("Photo").getValue().toString());
}
myAdapter.notifyDataSetChanged();
}
ListPetientFragment。JAVA 错误是:2021-11-17 18:41:02.417 29997-29997/?E/rtphonemedicat:运行时设置的未知位_标志:0x8000 2021-11-17 18:41:03.628 29997-30029/com。尼戈特。smartphonemedicate E/GED:无法获取GED日志Buf,错误(0)2021-11-17
这是我在片段中的代码: 这是从LogCat得到的 没有连接适配器跳过布局 观赏者 我在model类中设置getter和setter方法。(holder类所必需变量)
知道是什么引起的吗?
我正在尝试在片段中使用回收器视图,但我遇到一个问题,我的列表没有出现,我有这个错误: e/recycle view:未连接适配器;跳过布局 我检查了解决方案,显然问题出现在: > < li > < p > RecyclerView在适配器后初始化 绑定和设置回收器在“创建”查看“而不是”创建“中查看 但我注意到了,我尝试了其他选择,我仍然面临着同样的问题。 这是我的片段代码: XML: 列表适配器
我一直收到错误“RecycleView:未附加适配器;跳过布局”当显示RecyclView列表时。我有3个选项卡,其中一个选项卡有一个从SQLite数据库填充的RecyclView列表。我没有收到任何崩溃,数据在视图中显示正确,但我仍然收到这个错误。 我以为这只是一个警告,因为数据正确到位,但当我尝试onClick时,它不起作用,我确信它与此错误有关。 我知道这个问题以前被问过很多次,但我检查了大
我制作了一个基本的购物清单应用程序,它利用回收器视图来显示列表项目。我正在尝试使用带有片段的导航添加设置屏幕。我遇到了我的回收器视图的问题 主活动.kt HomeFragment.kt 设置Fragment.kt activity_main.xml fragment\u home.xml navigation.xml 不确定是否需要更多信息。提前道歉-我是android studio的新手