Question

I am using Android Amazing ListView to create a custom ListView with sticky headers. In this library, the data is being set inside Data.java class. What I need to do is, I have to pass the values for headers and list data for the headers from the database that I am creating locally. I am able to set the headers, however, I am not able to pass the list data according to those headers. The list data being populated is passed in the below format :

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"),
                    },
            };

I need to know, how can I create a jagged array like this from the data that I am retrieving from the database. I am able to get the data according to the headers, but I need to pass it in this format, in order to arrange the data under the headers accordingly. Hope to get a help soon.

Was it helpful?

Solution

For getting the values from the database and create a jagged array, you may do something like below:

Take an ArrayList and store all the indexes in it.

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());
}

Then you can generate the jagged array by using below method

private void mGenerateString(String[] mCurrString, int pos, int size)
{
    mStr[pos] = mCurrString;
    Log.e("", "string array : "+mStr[pos]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top