• 14
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I am trying to figure out a way to have my Activity decide which fragment to choose. What I have is a list of fragments and when you click on any of them they all display the same thing. I want to be able to display my 3 different fragments I have starting with one and going to the last, basically just repeating the 3 over and over.

My activity code looks like this

package com.example.ddursteler1.workouttracker;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;

import java.util.List;
import java.util.UUID;

public class WorkoutActivity extends SingleFragmentActivity {

    public static final String EXTRA_WORKOUT_ID = "com.example.ddursteler1.workouttracker.workout_id";

    private static UUID mUUID;


    public static Intent newIntent(Context packageContext, UUID workoutId) {
        Intent intent = new Intent(packageContext, WorkoutActivity.class);
        intent.putExtra(EXTRA_WORKOUT_ID, workoutId);
        return intent;
    }

    @Override
    protected Fragment createFragment() {
        UUID workoutId = (UUID) getIntent().getSerializableExtra(EXTRA_WORKOUT_ID);

        Log.d("createFragment UUID", workoutId.toString());
        return WorkoutFragment1.newInstance(workoutId);
    }
}

I want WorkoutFragment1 to be the first item in the fragment list, WorkoutFragment2 the second, WorkoutFragment3 the third and then repeat.

I have been following The Big Nerd Ranch programming book, so it is very similar to the CriminalIntent app. Any help is appreciated.

You are opening only WorkoutFragment1. You can create other fragments. And you should check in your activity like this.

    UUID workoutId = (UUID) 
    getIntent().getSerializableExtra(EXTRA_WORKOUT_ID);

    Log.d("createFragment UUID", workoutId.toString());
    if(workoutId==idOfWorkoutFragment1){
       return WorkoutFragment1.newInstance();
    }else if(...){
    ....
    ....
    }
  • 1
Reply Report