我无法将附件从 listView 保存到我的数据库中。我想保存附加的文件名、描述、uploadBy 和 dateUploaded,但由于某些原因,我无法成功保存。我保存过程中的代码是否正确?
String ReportCode = tv_Code.getText().toString();
String attachedFile = textViewTitle.getText().toString();
String attachedDescription = txt_Desc.getText().toString();
String attachedURI = tv_Uri.getText().toString();
String attachedUploadedBy = tv_CreatedBy.getText().toString();
String attachedDateUploaded = tv_DateCreated.getText().toString();
//SAVE All Attachment
databaseHandler.SaveAttach(new Cons_Attach (ReportCode, attachedFile, attachedURI, attachedDescription, attachedUploadedBy, attachedDateUploaded));
Toast.makeText(getApplicationContext(), ReportCode + "\n" + attachedFile + "\n" + attachedURI + "\n" + attachedDescription
+ "\n" + attachedUploadedBy + "\n" + attachedDateUploaded, Toast.LENGTH_SHORT);
填充 ListView
//Method in populating to List View
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View rowView = null;
try{
rowView = inflater.inflate(resource, null, true);
textViewTitle = (TextView) rowView.findViewById(to[0]);
txt_Desc = (EditText) rowView.findViewById(to[1]);
tv_CreatedBy = (TextView) rowView.findViewById(to[2]);
tv_DateCreated= (TextView) rowView.findViewById(to[3]);
final TextView tv_Action = (TextView) rowView.findViewById(to[4]);
final TextView tv_rowId = (TextView) rowView.findViewById(to[5]);
tv_Uri = (TextView)rowView.findViewById(to[6]);
final String FileKey = from[0];
String DescKey = from[1];
String UploadedByKey = from[2];
String DateUploadKey = from[3];
String ActionKey = from[4];
final String idKey = from[5];
String FileUri = from[6];
final String FileName = unfilteredValues.get(position).get(FileKey).toString();
String Desc = unfilteredValues.get(position).get(DescKey).toString();
String UploadedBy = unfilteredValues.get(position).get(UploadedByKey).toString();
String DateUpload = unfilteredValues.get(position).get(DateUploadKey).toString();
String Action = unfilteredValues.get(position).get(ActionKey).toString();
String AttachId = unfilteredValues.get(position).get(idKey).toString();
String FileNameUri = unfilteredValues.get(position).get(FileUri).toString();
textViewTitle.setText(FileName);
txt_Desc.setText(Desc);
tv_CreatedBy.setText(UploadedBy);
tv_DateCreated.setText(DateUpload);
tv_Action.setText(Action);
tv_rowId.setText(AttachId);
tv_Uri.setText(FileNameUri);
}catch (Exception e){
e.printStackTrace();
}catch (OutOfMemoryError E){
E.printStackTrace();
}
return rowView;
数据库处理程序.java
public void SaveAttach(Cons_Attach save){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Constants.REPORT_CODE, save.getReportCode()); // Save Report Code
values.put(Constants.ATTACH_FILENAME, save.getFile()); // Save File
values.put(Constants.ATTACH_FILELOCATION, save.getURI()); // Save URI
values.put(Constants.ATTACH_DESCRIPTION, save.getDescription()); // Save Description
values.put(Constants.ATTACH_CREATEDBY, save.getUploadedBy()); // Save UploadedBy
values.put(Constants.ATTACH_DATECREATED, save.getDateUploaded()); // Save Date Upload
db.insert(Constants.TABLE_ATTACH, null, values);
db.close();
}