我有3个数据库列表,我想将它们合并为一个并将数据显示到列表视图中,如下所示:
vathmoss + " " firstnames + " " +lastnames
现在我只显示名字...
Cursor c = database.rawQuery("Select * From " + PDFDatabaseManager.DATABASE_USERS_TABLE + ";", null);
ArrayList<String> vathmoss = new ArrayList<>();
ArrayList<String> firstnames = new ArrayList<>();
ArrayList<String> lastnames = new ArrayList<>();
while (c.moveToNext()) {
vathmoss.add(c.getString(0));
firstnames.add(c.getString(1));
lastnames.add(c.getString(2));
}
c.close();
final ListView listUser = (ListView) popup.findViewById(R.id.listview_user);
if (!vathmoss.isEmpty() && !firstnames.isEmpty() && !lastnames.isEmpty()) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.context, android.R.layout.simple_list_item_1,firstnames);
listUser.setAdapter(adapter);
}
答案 0 :(得分:0)
执行以下操作:
Cursor c = database.rawQuery("Select * From " +
PDFDatabaseManager.DATABASE_USERS_TABLE + ";", null);
ArrayList<String> vathmoss = new ArrayList<>();
ArrayList<String> firstnames = new ArrayList<>();
ArrayList<String> lastnames = new ArrayList<>();
ArrayList<String> mergednames = new ArrayList<>();
while (c.moveToNext()) {
vathmoss.add(c.getString(0));
firstnames.add(c.getString(1));
lastnames.add(c.getString(2));
mergednames.add(c.getString(0) + " " + c.getString(1) + " " + c.getString(2))
}
c.close();
final ListView listUser = (ListView) popup.findViewById(R.id.listview_user);
if (!vathmoss.isEmpty() && !firstnames.isEmpty() && !lastnames.isEmpty()) {
//In the below line, pass mergednames instead of firstname as last parameter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.context, android.R.layout.simple_list_item_1,mergednames);
listUser.setAdapter(adapter);
}