gpt4 book ai didi

android firebase 实时数据库问题(recyclerview,onclick 按钮,删除)

转载 作者:行者123 更新时间:2023-12-04 08:34:52 25 4
gpt4 key购买 nike

我希望在单击 item1 上的按钮时删除 item1 的数据。
但是 mDatabase.getReference("Choicestore").child(String.valueOf(arrayList.get(position)));我不知道如何处理这部分。
database image, I want the data of item1 to be deleted when the button on item1 is clicked. and I want the data of item2 to be deleted when the button on item2 is clicked.
我希望在单击 item1 上的按钮时删除 item1 的数据。我希望在单击 item2 上的按钮时删除 item2 的数据。

@Override
public void onBindViewHolder(@NonNull final ChoicestoreViewHolder holder, final int position) {

Glide.with(holder.itemView)
.load(arrayList.get(position).getChoicestore_img())
.into(holder.choicestore_img);
holder.choicestore_name.setText("storename : " + arrayList.get(position).getChoicestore_name());
holder.choicestore_time.setText("opentime : " + arrayList.get(position).getChoicestore_time());
holder.choicestore_breaktime.setText("breaktime : " +arrayList.get(position).getChoicestore_breaktime());
holder.choicestore_number.setText("storenumber : " + arrayList.get(position).getChoicestore_number());

holder.choicestore_delete.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {

mDatabase = FirebaseDatabase.getInstance();
dataRef = mDatabase.getReference("Choicestore").child(String.valueOf(arrayList.get(position)));

dataRef.removeValue();

}
});
}

我使用下面的答案进行编码,但出现此错误。

Error Image
@Override
public void onBindViewHolder(@NonNull final ChoicestoreViewHolder holder, final int position) {

Glide.with(holder.itemView)
.load(arrayList.get(position).getChoicestore_img())
.into(holder.choicestore_img);
holder.choicestore_name.setText("매장명 : " + arrayList.get(position).getChoicestore_name());
holder.choicestore_time.setText("운영시간 : " + arrayList.get(position).getChoicestore_time());
holder.choicestore_breaktime.setText("브레이크타임 : " +arrayList.get(position).getChoicestore_breaktime());
holder.choicestore_number.setText("매장번호 : " + arrayList.get(position).getChoicestore_number());

holder.choicestore_delete.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View view) {
final String NAme= arrayList.get(position).getChoicestore_name();


dataRef.orderByChild("choicestore_name")
.equalTo( NAme )
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
String clubkey = childSnapshot.getKey();

Log.d(TAG, "KEY = " + clubkey );


childSnapshot.getRef().removeValue();


}

}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}

});
}
});



}

这是发生错误的代码。

最佳答案

holder.choicestore_delete.setOnClickListener

final String NAme= arrayList.get(position).getChoicestore_name();


mDatabasesliderRef.orderByChild("choicestore_name")
.equalTo( NAme )
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
String clubkey = childSnapshot.getKey();

Log.d( TAG, "KEY = " + clubkey );


childSnapshot.getRef().removeValue();


}

}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}

});

关于android firebase 实时数据库问题(recyclerview,onclick 按钮,删除),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64843616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com