大家好我如何删除自定义列表视图中的单击项目。我无法删除Firebase数据。Android使用自定义列表视图删除Firebase数据
这里是学生活动,所有学生将出现在列表视图定制我要上点击删除
@覆盖 保护无效在onStart(){ super.onStart();
Query query = databaseReference.orderByChild("type").equalTo("student");
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
list.clear();
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){
ModelClass Mod = dataSnapshot1.getValue(ModelClass.class);
list.add(Mod);
}
final CustomAdapterClassStudent adapterClassCompany = new CustomAdapterClassStudent(AllStudents.this , list);
l1.setAdapter(adapterClassCompany);
l1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
这里是我的自定义适配器类数组适配器扩展
@NonNull
@Override
public View getView(final int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
final View listview = inflater.inflate(R.layout.customadapter , null , true);
TextView textViewName = (TextView) listview.findViewById(R.id.textName);
TextView textViewAdd = (TextView) listview.findViewById(R.id.textAdd);
TextView textViewBio = (TextView) listview.findViewById(R.id.textBio);
final ModelClass Mod = compniesModel.get(position);
textViewName.setText(Mod.name);
textViewAdd.setText(Mod.cgpa);
textViewBio.setText(Mod.bio);
return listview;
这里是ModelClass .. ModelClass包含学生和公司领域的火力点,以节省..下面检查图像
public class ModelClass {
public String name;
public String email;
public String cgpa;
public String age;
public String bio;
public String type;
public String compName;
public String compAdd;
public String compAbout;
public ModelClass(){}
public ModelClass(String name, String email, String cgpa, String age, String bio,String type) {
this.name = name;
this.email = email;
this.cgpa = cgpa;
this.age = age;
this.bio = bio;
this.type = type;
}
public ModelClass(String compName, String compAdd, String compAbout , String type) {
this.compName = compName;
this.compAdd = compAdd;
this.compAbout = compAbout;
this.type = type;
}
}
Here is the Database Image Click on this
你能告诉我们你的ModelClass吗? – Pipiks
嘿Pipiks,我添加我的ModelClass的问题..我正确能够通过ModelClass保存我的数据,如果用户在Firebase数据保存类型“公司”,如果用户说“公司”,否则“学生”..但我无法删除在哪里我的所有学生都出现在自定义列表中 –
如果你这么说,我会在GitHub上更新我的代码,这样你可以检查我的所有代码..如果你帮我,我会很高兴..我浪费了4个小时,但现在我自己失败 –