我正在制作一个便笺应用程序,并且我的便笺已自动保存到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);
}
});
}
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)