我正在使用 SQlite 数据库。我创建了 2 个表并填充它们(工作正常)并使用那里的数据在列表视图中显示。当第一次列表适配器填充列表视图时,将 newDATA 变量显示为零。一些数据。但是当我回去并进一步开始该活动时 newDATA 具有正确的值。. 我使用下面的代码
public ArrayList<HashMap<String, Object>> GetDataFirst(String id) {
ArrayList<HashMap<String, Object>> firstvariable = new ArrayList<HashMap<String, Object>>();
Cursor c =sdb.rawQuery("Select * from table_name ",new String[]{id} );
String[] colums = c.getColumnNames();
while (c.moveToNext()) {
HashMap<String, Object> record = new HashMap<String, Object>();
for (int i = 0; i < colums.length; i++) {
record.put(colums[i], c.getString(c.getColumnIndex(colums[i])));
}
{
ArrayList<HashMap<String, String>> now_add = GetmainData(id, record.get("vget").toString());
record.put("NewDATA", now_add);
hint.add(record);
}
}
}
c.close();
return firstvariable ;
}
public ArrayList<HashMap<String, String>> GetCluesDataVerical(String id,String vhid) {
ArrayList<HashMap<String, String>> hint = new ArrayList<HashMap<String, String>>();
Cursor c = sdb.rawQuery("SELECT * FROM table_data", new String[] {id,vhid});
String[] colums = c.getColumnNames();
while (c.moveToNext()) {
HashMap<String, String> record_add = new HashMap<String, String>();
for (int i = 0; i < colums.length; i++) {
record_add.put(colums[i], c.getString(c.getColumnIndex(colums[i])));
}
hint.add(record_add);
}
c.close();
return hint;
}
在列表适配器中,我将其称为如下:
recordData=context.crossDatabaseAdapter.GetDataFirst(value);
wArray = (ArrayList<HashMap<String, String>>) recordData.get(position).get("NewDATA");
我尝试了很多但仍然没有任何解决方案。