加载和编辑先前填充的特定数据

时间:2019-05-26 15:21:34

标签: java android firebase firebase-realtime-database

我正在制作一个便笺应用程序,并且我的便笺已自动保存到Firebase数据库。到目前为止,用户可以自己制作笔记,但不能对其进行编辑。我希望该应用程序在单击时打开相同的注释(这意味着标题和说明字段将保留上次输入的数据),以便他们可以对其进行编辑,但不知道如何,我什至不知道该如何在线查找这是我的第一个项目。

新笔记创建和自动更新

 (一个监听器标题,一个监听器正文)

public class NewNoteActivity extends AppCompatActivity{


    private EditText editText, etd;
    private FirebaseAuth fAuth;
    final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference()/* THIS!*/.child("Users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("posts").push();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_note);

        editText = findViewById(R.id.etx);
        etd = findViewById(R.id.etdx);



        final Map<String, Object> map = new HashMap<>();
        map.put("id", databaseReference.getKey());

        editText.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {

                map.put("title", editText.getText().toString());
                databaseReference.setValue(map);


            }
        });

        etd.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {

                map.put("desc", etd.getText().toString());

                databaseReference.setValue(map);

            }

        });
        }

显示注释

 (并设置onClick操作)

 adapter = new FirebaseRecyclerAdapter<Model, ViewHolder>(options) {
            @Override
            public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.list_item, parent, false);

                return new ViewHolder(view);
            }


            @Override
            protected void onBindViewHolder(final ViewHolder holder, final int position, final Model model) {

                holder.setTxtTitle(model.getmTitle());
                holder.setTxtDesc(model.getmDesc());
                //holder.setmId(model.getmId());

                holder.root.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        //Here I need to find somehow to get back to the note I clicked on

                    }
                });
            }

        };
        recyclerView.setAdapter(adapter);

这是列表的外观

由于我还无法发布图片,因此:https://i.imgur.com/MDQ15a6.png
每个方块都是一个音符。 (忽略B)

0 个答案:

没有答案