0

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"
4
  • Two dimension could be enough no ? Commented Nov 17, 2014 at 17:14
  • @ToYonos yes two would suffice as I said I dont think I understanding how it works in this context. Commented Nov 17, 2014 at 17:19
  • @Kick How do I add the lists complete_time and rest_time to list Exercise Commented Nov 17, 2014 at 17:21
  • Since you are using an object-oriented programming language, you might want to consider using some objects, instead of multidimensional arrays of Strings. Commented Nov 17, 2014 at 17:23

1 Answer 1

2

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.