所以我正在处理我的应用程序,并尝试将一个项目添加到RecyclerView,但出于一些遗憾的原因,每当我尝试更新项目时,它都无效。 (好吧,一半不行) 我在图标上添加了一个onClickListener,因此无论何时按下该图标,都会打开一个包含该信息的对话框。情况就是这样:
onBindViewHolder方法
recyclerVH.pencil.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("User Interface", "updateNote called!");
// Opens Dialog to update Note and Alarm
// TODO Open Activity instead
updateDialog = new MaterialDialog.Builder(context)
.title("Rewrite Note")
.customView(R.layout.note_update_screen, false)
.positiveText("Update")
.negativeText("Nevermind")
.forceStacking(false)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(MaterialDialog dialog, DialogAction which) {
updateNote(updatedTitle, updatedContent, position);
}
})
.build();
//noinspection ConstantConditions
updateTitle = (EditText)updateDialog.getCustomView().findViewById(R.id.updateNoteTitle);
updateContent = (EditText)updateDialog.getCustomView().findViewById(R.id.updateNoteContent);
// Set the text for the title using current info
updateTitle.setText(currentTitle);
updateContent.setText(currentContent);
updateButton = updateDialog.getActionButton(DialogAction.POSITIVE);
// TODO FIX BUG - BLANK CONTENT WHEN TITLE EDITED
updateTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
updatedTitle = currentTitle;
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
/*if (s == null) {
updatedTitle = currentTitle;
} */
updatedTitle = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
// isTitleSet = true;
updateButton.setEnabled(true);
}
});
updateContent.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
updatedContent = currentContent;
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
/*if (s == null) {
updatedContent = currentContent;
} */
updatedContent = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
// isContentSet = true;
updateButton.setEnabled(true);
}
});
/*if (isTitleSet || isContentSet) {
Log.d("RecyclerAdapter", "Note updated on: " + updatedTitle);
updateButton.setEnabled(true);
}*/
updateDialog.show();
updateButton.setEnabled(false);
}
});
updateNote方法
public void updateNote(String noteTitle, String noteContent, int position) {
Info updatedNote = data.get(position);
Log.d("RecyclerView", "Note updated on: " + updatedNote);
updatedNote.setTitle(noteTitle);
updatedNote.setContent(noteContent);
notifyItemChanged(position);
DBInfo dbInfo = new DBInfo(context);
dbInfo.updateNote(updatedNote);
}
如果你能帮助我,我会永远感激。谢谢!
方面问题:你什么时候使用术语'故障'或'bug'以及在什么情况下?