【问题标题】:List view is not populating with database when first time activity start首次活动开始时,列表视图未填充数据库
【发布时间】:2013-05-01 15:32:49
【问题描述】:

我正在使用 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");

我尝试了很多,但仍然没有任何解决方案。

【问题讨论】:

    标签: android sqlite listview listadapter


    【解决方案1】:

    当您停止应用程序时,您必须使用实例状态来保存列表适配器的内容,当应用程序启动时,您必须检查是否可以通过实例状态检索数据,否则从数据库加载数据,这可能会解决您的问题问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多