user3772063
user3772063

Reputation: 39

Android Multidimensional array

I have searched found a few answers but I am not quite sure I understand them. I want a multidimensional array or the equivalent of say string[0][1][1].

Here is what I have:

   public List<List<List<String>>> loadCompleteExercises(String workout)
{
    List<List<List<String>>> listExercises = new ArrayList<List<List<String>>>();
    List<String> complete_time = new ArrayList<String>();
    List<String> rest_time = new ArrayList<String>();

    db = dbHelper.getReadableDatabase();
    Cursor c = db.rawQuery("SELECT complete_time, rest_time FROM tbl_exercises WHERE workout = '"+workout+"';", null);
    c.moveToFirst();
    while(!c.isAfterLast()) {
        try {
            if(c.isNull(c.getColumnIndex("exercise"))) {
                complete_time.add("00:00:05");
                rest_time.add("00:00:00");
            }else {
                complete_time.add(c.getString(c.getColumnIndex("complete_time")));
                rest_time.add(c.getString(c.getColumnIndex("rest_time")));
            }
        }catch (NullPointerException e)
        {
            Log.d("GET EXERCISES ERROR: ", e.toString());
        }
        c.moveToNext();
    }

    //listExercises.add();

    return listExercises;
}

--- I want to add complete_time and rest_time to listExercises so that I can say do the following

listExercises.get(i).get(j) to yield the below

1 "00:00:05" "00:00:00"
2 "00:10:00" "00:10:00" 
... 
n "xx:xx:xx" "xx:xx:xx"

Upvotes: 0

Views: 601

Answers (1)

ToYonos
ToYonos

Reputation: 16843

Try this, use a holder for both time, add them in a List

private class TimeHolder
{
    public String completeTime;
    public String restTime;
}

public List<TimeHolder> loadCompleteExercises(String workout)
{
    List<TimeHolder> listExercises = new ArrayList<TimeHolder>();

    db = dbHelper.getReadableDatabase();
    Cursor c = db.rawQuery("SELECT complete_time, rest_time FROM tbl_exercises WHERE workout = '"+workout+"';", null);
    c.moveToFirst();
    while(!c.isAfterLast()) {
        try
        {
            TimeHolder holder = new TimeHolder();
            if(c.isNull(c.getColumnIndex("exercise"))) {
                holder.completeTime = "00:00:05";
                holder.restTime = "00:00:00";
            }else {
                holder.completeTime = c.getString(c.getColumnIndex("complete_time"));
                holder.restTime = c.getString(c.getColumnIndex("rest_time"));
            }
            listExercises.add(holder);
        }
        catch (NullPointerException e)
        {
            Log.d("GET EXERCISES ERROR: ", e.toString());
        }
        c.moveToNext();
    }

    return listExercises;
}

Upvotes: 2

Related Questions