我创建了一个包含recyclerview
的应用程序,并根据用户的点击从recyclerview arrayList
的{{1}}中添加了数据,然后根据用户的点击编辑,删除了alertDilog
中的数据。但是当我将我的应用程序连接到AlertDilog
时,我的应用程序无法正常工作。
Recyclerview适配器:
firebase Database
和物品类别:
public class recyclerviewadapter extends RecyclerView.Adapter<recyclerviewadapter.Viewholder> {
ArrayList<customitem> datalist;
vonclick mclick;
@NonNull
@Override
public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recyclerviewexdesign,parent,false);
return new Viewholder(v,mclick);
}
public recyclerviewadapter(ArrayList<customitem> datalist) {
this.datalist = datalist;
}
@Override
public void onBindViewHolder(@NonNull Viewholder holder, int position) {
customitem n = datalist.get(position);
holder.productname.setText(n.getproductname());
}
@Override
public int getItemCount() {
return datalist.size();
}
public class Viewholder extends RecyclerView.ViewHolder {
TextView productname;
public Viewholder(@NonNull View itemView, final vonclick listener) {
super(itemView);
productname = itemView.findViewById(R.id.titleid);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener!=null){
int possition =getAdapterPosition();
if (possition !=RecyclerView.NO_POSITION){
listener.cclick(possition);
}
}
}
});
}
}
public interface vonclick{
void cclick(int possition);
}
public void recyclerviewonclicl(vonclick possition){
mclick=possition;
}
}
最后一个主班:
public class customitem {
String productname,size,price,box;
int kg;
public customitem(){
}
public customitem(String productname, String size,String price,String box,int kg) {
this.productname = productname;
this.size = size;
this.price = price;
this.box = box;
this.kg = kg;
}
public String getproductname() {
return productname;
}
public void setproductname(String productname) {
this.productname = productname;
}
public String getsize() {
return size;
}
public void setsize(String size) {
this.size = size;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getBox() {
return box;
}
public void setBox(String box) {
this.box = box;
}
public int getKg() {
return kg;
}
public void setKg(int kg) {
this.kg = kg;
}
}