列表视图不显示

Listview not showing

我有一个包含唯一 ID 的整数 ArrayList。

我有这个方法来填充列表视图。

public void getDataDetails(int id)
    {
            Cursor c = db.getData(id);
            String[] from = new String[]{ID, name};
            int[] to = new int[]{R.id.layout_id, R.id.layout_name};

            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.layout, c, from, to, 0);
            listview.setAdapter(adapter);
            adapter.notifyDataSetChanged();
    }

在我的 onCreate 方法中我有这段代码。变量数据是我的 ArrayList,它的值为 1 和 2。

listview= (ListView) findViewById(R.id.listView);
for (int x=0; x < data.size(); x++)
{
      getDataDetails(data.get(x));
}

我的问题是唯一显示的数据是 x=2 时的数据。应该有两个列表视图包含 x=1 和 x=2 中的数据。有帮助吗?

把这个放在 onCreate()

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.layout, c, from, to, 0);
listview.setAdapter(adapter);