Firebase数据库:无法删除Firebase数据库Android

时间:2017-05-23 05:05:31

标签: android firebase firebase-realtime-database

我想从列表视图中提取值以在查询行中传递它

public boolean onContextItemSelected(MenuItem item) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();


        Toast.makeText(Weekly_update.this,item.getTitle(),Toast.LENGTH_LONG).show();
        switch (item.getItemId()) {
            case R.id.delete:

                final AlertDialog dialog = new AlertDialog.Builder(this)
                        .setTitle("R u sure??")
                        .setView(R.layout.custom_dialog_delete)
                        .create();

                dialog.show();

                Button b=(Button)dialog.findViewById(R.id.cdb2);

                b.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {


                        DatabaseReference ref = FirebaseDatabase.getInstance().getReference();

                        //i want to get the xxx from the listview when i press the screen
                        Query applesQuery = ref.child("WEEK WORK").orderByChild("date").equalTo("xxxxx");


                        applesQuery.addListenerForSingleValueEvent(new ValueEventListener() {
                            @Override
                            public void onDataChange(DataSnapshot dataSnapshot) {
                                for (DataSnapshot appleSnapshot: dataSnapshot.getChildren()) {

                                    appleSnapshot.getRef().removeValue();


                                }
                            }

                            @Override
                            public void onCancelled(DatabaseError databaseError) {
                                Log.e("fail 123..", "onCancelled", databaseError.toException());
                            }
                        });



                        dialog.dismiss();

                    }

                });
            default:
                return super.onContextItemSelected(item);
        }

1 个答案:

答案 0 :(得分:0)

您添加以下代码:

databaseReference = FirebaseDatabase.getInstance().getReference().child("question");

keyValues.get(position)给了我问题的标题

databaseReference.child(keyValues.get(position)).removeValue();