Android:如何创建一个从数据库中动态获取值的锯齿状数组



我正在使用Android Amazing ListView创建一个带有粘性标题的自定义ListView。在这个库中,数据是在data.java类中设置的。我需要做的是,我必须从本地创建的数据库中传递头的值和头的列表数据。我可以设置标题,但是,我不能根据这些标题传递列表数据。正在填充的列表数据以以下格式传递:

Composer[][] composerss = {
                    {
                        new Composer("Thomas Tallis"),
                        new Composer("Josquin Des Prez"),
                        new Composer("Pierre de La Rue"),
                    },
                    {
                        new Composer("Johann Sebastian Bach"),
                        new Composer("George Frideric Handel"),
                        new Composer("Antonio Vivaldi"),
                        new Composer("George Philipp Telemann"),
                    },
                     {
                        new Composer("Franz Joseph Haydn"),
                        new Composer("Wolfgang Amadeus Mozart"),
                        new Composer("Barbara of Portugal"),
                        new Composer("Frederick the Great"),
                        new Composer("John Stanley"),
                        new Composer("Luise Adelgunda Gottsched"),
                        new Composer("Johann Ludwig Krebs"),
                        new Composer("Carl Philipp Emanuel Bach"),
                        new Composer("Christoph Willibald Gluck"),
                        new Composer("Gottfried August Homilius"),
                    },
                    {
                        new Composer("Ludwig van Beethoven"),
                        new Composer("Fernando Sor"),
                        new Composer("Johann Strauss I"),
                    },
                    {
                        new Composer("Ludwig van Beethoven"),
                        new Composer("Fernando Sor"),
                        new Composer("Johann Strauss I"),
                    },
            };

我需要知道,如何从数据库中检索的数据中创建这样的锯齿状数组。我可以根据标题获取数据,但我需要以这种格式传递数据,以便相应地排列标题下的数据。希望能尽快得到帮助。

为了从数据库中获取值并创建锯齿状数组,您可以执行以下操作:

取一个ArrayList并将所有索引存储在其中。

for(int i = 0; i<myIndexList.size(); i++)
{
    String[] s = null;
    Log.e("", "current pos "+i);
    Cursor mCur2 = mDb.sGetMySectionListData(myIndexList.get(i));
    if(mCur2.getCount()>0)
        {
            s = new String[mCur2.getCount()];
            mCur2.moveToFirst();
            do
                {
                    s[mCur2.getPosition()] = mCur2.getString(mCur2.getColumnIndex("section_data")));
                }
            while(mCur2.moveToNext());
        }
    mCur2.close();
    mGenerateString(s, i, myIndexList.size());
}

然后您可以使用以下方法生成锯齿状阵列

private void mGenerateString(String[] mCurrString, int pos, int size)
{
    mStr[pos] = mCurrString;
    Log.e("", "string array : "+mStr[pos]);
}

最新更新