【发布时间】:2016-02-17 20:26:13
【问题描述】:
我正在使用下面的代码从我的SQLite db 行中检索两个参数,TITLE 和NOTE。我在allnotesArrayList 中列出了所有内容。
我现在要做的是通过电子邮件以干净的格式分享ArrayList。
DatabaseConnector dbConnector = new DatabaseConnector(MainActivity.this);
dbConnector.open();
c = dbConnector.ListAllNotesFull();
while(c.moveToNext()) {
Map<String, String> data = new HashMap<String, String>(2);
data.put(TITLE, c.getString(c.getColumnIndex(TITLE)));
data.put(NOTE, c.getString(c.getColumnIndex(NOTE)));
allnotes.add(data);
}
dbConnector.close();
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yy");
String formattedDate = df.format(c.getTime());
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
i.putExtra(Intent.EXTRA_SUBJECT, "My app: my workouts backup " + formattedDate);
i.putExtra(Intent.EXTRA_TEXT, allnotes.toString());
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
但我在邮件正文中得到的结果是:
[{note=blabla, title=test}, {note=gdgfg, title=test2}]
我应该改用数组吗?无论如何,我怎样才能将它格式化为一个干净的字符串?谢谢
编辑:我希望列表的格式很简单
标题
注意
(这里有空格)
标题
注意
等等。 (不需要加粗)
【问题讨论】:
-
在这里使用数组对您没有帮助。您需要按照您希望的方式手动对其进行格式化。请使用您想要的格式更新您的帖子。
-
嗨,感谢您的宝贵时间,现在编辑
标签: android arraylist format tostring