gpt4 book ai didi

android ArrayList 清理文本以通过电子邮件共享

转载 作者:行者123 更新时间:2023-11-30 01:33:21 25 4
gpt4 key购买 nike

我正在使用下面的代码从我的 SQLite 数据库行中检索两个参数,TITLENOTE。我在 allnotes ArrayList 中列出所有内容。我现在要做的是以干净的格式通过电子邮件共享 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}]

我应该改用数组吗?我怎样才能将它格式化为干净的字符串呢?谢谢


编辑:我希望列表的格式很简单

标题

注意

(此处空格)

标题

注意

等(粗体不需要)

最佳答案

您需要遍历 hashmap 并获取 Notes、Titles 值并将其附加到字符串中。您可能会感兴趣:

String noteTitleList = "";
for(Map<String, String> data: allnotes)
{
Iterator it = data.entrySet().iterator();
while (it.hasNext())
{
Map.Entry pair = (Map.Entry)it.next();
noteTitleList+= pair.getKey()+": "+pair.getValue()+"\n";
}
noteTitleList+= "\n";
}

在此 for 循环之后,您将获得所需格式的 NoteTitle 对列表。您可以在此之后调用 Intent。

编辑:为了适应您的格式,如下所示,我修改了上面的代码。

标题

注意

(此处空格)

标题

注意

关于android ArrayList 清理文本以通过电子邮件共享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35467020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com