我必须像这样在 ViewHolder 中获取 EditText 中包含的文本:
@Override
public void onClick(View v) {
holder.editTextComment = (EditText) v
.findViewById(R.id.editTextComment);
String comment = holder.editTextComment.getText()
.toString();
// String comment = new String("lol");
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyy");
SimpleDateFormat dt = new SimpleDateFormat("HH:mm");
String formattedDate = df.format(c.getTime());
String formattedTime = dt.format(c.getTime());
if (!comment.equalsIgnoreCase("")) {
switch (v.getId()) {
case R.id.buttonPostComment:
addItem(comment, formattedDate, formattedTime, v,
holder);
break;
}
}
但是当我尝试将edittext文本插入字符串时,我的程序崩溃了,为什么?