Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8075743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:05:27+00:00 2026-06-05T15:05:27+00:00

I am having a little problem with Relative Layouts. I’m doing a project in

  • 0

I am having a little problem with Relative Layouts. I’m doing a project in which I have to read some values from a .CSV file and display them dynamically in a Relative Layout. I’ll put a couple of code snippets and images and then explain my problem.

First Code snippet:

package ekalavya.pratnala.quiz;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.StringTokenizer;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

public class QuizActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Beginning of variable declarations
    File quizSpecs = new File("mnt/sdcard/teacher.csv"); // Read the file
    BufferedReader csvReader = null;
    String line = ""; // Storing each line in a string
    StringTokenizer currentLine = null;
    int noOfQuestions = 0; // Number of questions in the quiz
    int time = 0; // Duration of the quiz
    int[][] quizData; // Storing the quiz specifications in an integer array
    int i = 0, j = 0; // Loop variables
    int[][] questionImages = {
            { R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,
                    R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h,
                    R.drawable.i, R.drawable.j },
            { R.drawable.a_checked, R.drawable.b_checked,
                    R.drawable.c_checked, R.drawable.d_checked,
                    R.drawable.e_checked, R.drawable.f_checked,
                    R.drawable.g_checked, R.drawable.h_checked,
                    R.drawable.i_checked, R.drawable.j_checked },
            { R.drawable.zero, R.drawable.one, R.drawable.two,
                    R.drawable.three, R.drawable.four, R.drawable.five,
                    R.drawable.six, R.drawable.seven, R.drawable.eight,
                    R.drawable.nine },
            { R.drawable.zero_checked, R.drawable.one_checked,
                    R.drawable.two_checked, R.drawable.three_checked,
                    R.drawable.four_checked, R.drawable.five_checked,
                    R.drawable.six_checked, R.drawable.seven_checked,
                    R.drawable.eight_checked, R.drawable.nine_checked } };
    // End of variable declarations

    try {
        csvReader = new BufferedReader(new FileReader(quizSpecs));
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        line = csvReader.readLine();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    currentLine = new StringTokenizer(line, ",");
    noOfQuestions = Integer.parseInt(currentLine.nextToken());
    time = Integer.parseInt(currentLine.nextToken());
    while (currentLine.hasMoreTokens())
        ;
    quizData = new int[noOfQuestions][6];
    for (i = 0; i < noOfQuestions; i++) {
        try {
            line = csvReader.readLine();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        currentLine = new StringTokenizer(line, ",");
        for (j = 0; j < 6; j++) {
            quizData[i][j] = Integer.parseInt(currentLine.nextToken());
        }
    }
    try {
        csvReader.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    ScrollView s1 = new ScrollView(this);
    RelativeLayout r1 = new RelativeLayout(this);
    for (i = 0; i < 2; i++) {
        switch (quizData[i][1]) {
        case 1:
        case 2:
            for (j = 0; j < quizData[i][2]; j++) {
                ImageView option = new ImageView(this);
                option.setImageResource(questionImages[0][j]);
                option.setId(j + (10 * (i + 1)));
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
                params.addRule(RelativeLayout.RIGHT_OF, j - 1
                        + (10 * (i + 1)));
                option.setLayoutParams(params);
                r1.addView(option, params);
            }
            break;
        }
    }
    s1.addView(r1, new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));
    this.setContentView(s1);
}
}

Image 1: https://www.dropbox.com/s/vzpilyotvgtipbb/pic2.png

Second Code snippet:

package ekalavya.pratnala.quiz;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.StringTokenizer;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

public class QuizActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Beginning of variable declarations
    File quizSpecs = new File("mnt/sdcard/teacher.csv"); // Read the file
    BufferedReader csvReader = null;
    String line = ""; // Storing each line in a string
    StringTokenizer currentLine = null;
    int noOfQuestions = 0; // Number of questions in the quiz
    int time = 0; // Duration of the quiz
    int[][] quizData; // Storing the quiz specifications in an integer array
    int i = 0, j = 0; // Loop variables
    int[][] questionImages = {
            { R.drawable.a, R.drawable.b, R.drawable.c, R.drawable.d,
                    R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h,
                    R.drawable.i, R.drawable.j },
            { R.drawable.a_checked, R.drawable.b_checked,
                    R.drawable.c_checked, R.drawable.d_checked,
                    R.drawable.e_checked, R.drawable.f_checked,
                    R.drawable.g_checked, R.drawable.h_checked,
                    R.drawable.i_checked, R.drawable.j_checked },
            { R.drawable.zero, R.drawable.one, R.drawable.two,
                    R.drawable.three, R.drawable.four, R.drawable.five,
                    R.drawable.six, R.drawable.seven, R.drawable.eight,
                    R.drawable.nine },
            { R.drawable.zero_checked, R.drawable.one_checked,
                    R.drawable.two_checked, R.drawable.three_checked,
                    R.drawable.four_checked, R.drawable.five_checked,
                    R.drawable.six_checked, R.drawable.seven_checked,
                    R.drawable.eight_checked, R.drawable.nine_checked } };
    // End of variable declarations

    try {
        csvReader = new BufferedReader(new FileReader(quizSpecs));
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        line = csvReader.readLine();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    currentLine = new StringTokenizer(line, ",");
    noOfQuestions = Integer.parseInt(currentLine.nextToken());
    time = Integer.parseInt(currentLine.nextToken());
    while (currentLine.hasMoreTokens())
        ;
    quizData = new int[noOfQuestions][6];
    for (i = 0; i < noOfQuestions; i++) {
        try {
            line = csvReader.readLine();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        currentLine = new StringTokenizer(line, ",");
        for (j = 0; j < 6; j++) {
            quizData[i][j] = Integer.parseInt(currentLine.nextToken());
        }
    }
    try {
        csvReader.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    ScrollView s1 = new ScrollView(this);
    RelativeLayout r1 = new RelativeLayout(this);
    for (i = 0; i < 1; i++) {
        switch (quizData[i][3]) {
        case 1:
        case 2:
            for (j = 0; j < quizData[i][2]; j++) {
                ImageView option = new ImageView(this);
                option.setImageResource(questionImages[0][j]);
                option.setId(j + (10 * (i + 1)));
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
                params.addRule(RelativeLayout.RIGHT_OF, j - 1
                        + (10 * (i + 1)));
                option.setLayoutParams(params);
                r1.addView(option, params);
            }
            break;
        }
    }
    s1.addView(r1, new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT));
    this.setContentView(s1);
}
}

Image 2: https://www.dropbox.com/s/itazcpshjzbza4t/pic1.png

When the loop in the switch case with variable ‘i’ is run only once, the second output comes. And if I run it twice, the first output comes. But that’s not what I want. I want the first output row to show below the second output row. I know something is wrong in the code but I don’t know how to rectify it. Please help me! Also, I want to know how to place those elements anywhere on the screen.

P.S. I haven’t been allowed to upload images because my reputation is less than 10 (I’m a newbie here). So, I put them on Dropbox and have put the links here. Sorry for the inconvenience.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:05:28+00:00Added an answer on June 5, 2026 at 3:05 pm

    I have solved this: I specified only the RIGHT_OF property before and hence it didn’t know where to place it vertically and so put it at the top. Specifying the BELOW property as well fixed the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a little problem implementing some jQuery into a page I am doing.
I'm having a little problem displaying data from a database... I have two database
I'm having a little problem with nginx and the Perl FCGI module. I have
I am having a new little problem; I have a little pointer called: int
I'm having a trouble with this little problem. Let's say, I have an array,
I have a little newbie problem that I cannot figure out, I am having
I'm having some difficulties with the following problem: I'm making a little game where
Im having a little problem with classes. Here is some of my code: //GameMap.h
I'm having a little problem with the css display property. I have the following
I am having a little problem here. I have a <script language =JavaScript runat=server>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.