Generic use of SimpleCursorAdapter
<p>I am building a database app which should make use of a generic mechanism to read its data and show it to in listview. I am relatively new to Android programming.</p>

<p>I am using the SimpleCursorAdapter but the problem is that I need to design in XML, the row layout view. But I do not want to do this. The reason is that I want the stuff to work generic against any table, like "SELECT * FROM ". Using the SimpleCursorAdapter I need to create a LinearLayout per table record, and add that id to to the constructor.</p>

<p>What I want is to programmatically create the LinearLayout and pass that id to the constructor, but this is not working. I get the ResourceNotFoundException. When trying to add TextViews to the ContentView, this is not working either, the components do not show.</p>

<p>Is this possible at all?</p>

<p>Thanks,
Coenos</p>

<p>Edit:</p>

<p>this is the stacktrace</p>

<pre><code>09-15 16:43:43.547: ERROR/AndroidRuntime(13273): FATAL EXCEPTION: main
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):       android.content.res.Resources$NotFoundException: Resource ID #0x4
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.content.res.Resources.getValue(Resources.java:892)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.content.res.Resources.loadXmlResourceParser(Resources.java:1869)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.content.res.Resources.getLayout(Resources.java:731)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.ResourceCursorAdapter.newView(ResourceCursorAdapter.java:79)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.CursorAdapter.getView(CursorAdapter.java:182)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.AbsListView.obtainView(AbsListView.java:1427)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1273)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.ListView.onMeasure(ListView.java:1184)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.view.View.measure(View.java:8226)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.view.View.measure(View.java:8226)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.view.View.measure(View.java:8226)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
09-15 16:43:43.547: ERROR/AndroidRuntime(13273):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
</code></pre>

<p>This is the code</p>

<pre><code>Cursor cur = dbAdapter.findAllRecordsByTableName(tableName);

    List&lt;String&gt; columnList = dbAdapter.findColumnsByTableName(tableName);

    String[] columns = columnList.toArray(new String[0]);

    startManagingCursor(cur);

    LinearLayout layout = new LinearLayout(this);
    layout.setId(4);
    int[] to = new int[columns.length];
    int i = 5;
    for (String column : columns) {
        Log.d("this", "column in list :" + column);
        TextView view = new TextView(this);

        view.setId(i);
        to[i-5] = i;
        i++;
        /*
        this.addContentView(view, new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                */
        layout.addView(view);
    }

    Log.d("buildContent2", "total children "+layout.getChildCount());

    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
            layout.getId(), cur, columns, to);

    this.setListAdapter(mAdapter);
</code></pre>

<p>I understand that the LinearLayout with id=4 is not know to the Context, but how can I make it known? Do I need to add it to the Context, but how? This is where my Android knowledge is lacking....</p>
