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

  • Home
  • SEARCH
  • 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 6963761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:50:11+00:00 2026-05-27T15:50:11+00:00

I am having problems writing a piece of code for android. I am using

  • 0

I am having problems writing a piece of code for android. I am using the eclipse development environment. What I am trying to accomplish is to have the days of the week evenly spaced out on the first row of a table (with six rows). I can not figure out how to make it so that the words actually spread out, and not just stick together in a group. (yes I have tried using weights). My code is as follows. I apologize in advance for any misspellings in the question or comments in the code.

package A3.cal;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TableLayout;
import android.widget.TableRow;

public class A3Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); //it works dont touch it...
    setContentView(R.layout.main); //old Content View
    MonthView(); //setup the initial view
}

public void MonthView(){
    TableRow[] tableRows = new TableRow[6]; //create table rows for the table
    LinearLayout[] dayHeaderFrames = new LinearLayout[7]; //create the frame layouts for the table headers
    TextView[] days = new TextView[7]; //create new text views array
    days = populateDays(0); //make the textviews say the proper days (this can be faster by manipulating the strings and then adding to textview)
    TableLayout monthView = (TableLayout) findViewById(R.id.monthView); //find month View in the xml file
    LinearLayout headerLayout = new LinearLayout(this); //create the linear layout that will hold the frame layouts for the text views**
    headerLayout.setBackgroundColor(Color.WHITE); //make the linear layouts white
    LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f); //create the layout perameters for childeren

    for(int i = 0; i < 6; i++){ //create the table rows
        tableRows[i] = new TableRow(this); //create the new rows
    }

    tableRows[0].addView(headerLayout); //add the header layout to the first row
    tableRows[0].setBackgroundColor(Color.RED); //set the background table row (only the first one which I am concentrating on) to red
    monthView.setBackgroundColor(Color.BLUE); // make the table blue

    for(int i = 0; i < 7; i++){ //add the headers to the month day header row
        dayHeaderFrames[i] = new LinearLayout(this); //create new frames
        headerLayout.addView(dayHeaderFrames[i], ll); //add the frames to the first row in the table
        dayHeaderFrames[i].addView(days[i]); //add the textview objects to the frames (the text view objects already have the correct text from when populate days was called)
    }

    for(int i = 0; i < 6; i++){ //add the rows to the month view
        monthView.addView(tableRows[i]); //add the new rows to the table
    }
}

public TextView[] populateDays(int startDay){
    TextView[] daysTextViewArr = new TextView[7]; //create a textview array
    String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; //days of the week

    for(int i = 0; i < 7; i++){ //put the days into the order based upon the start day
        daysTextViewArr[i] = new TextView(this); //create a new text view object

        //the following logic puts the days into order
        int day = i + startDay; 
        if(day > 6){ //if the day will exceed the array put it back to the begining
            day = day - 7; 
        }

        daysTextViewArr[i].setText(days[i]); //set the text in the text view to the propper day
    }

    return daysTextViewArr;
}

}

And the XML Layout in main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">


<TableLayout
    android:id="@+id/monthView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</TableLayout>

To recap The Code works except for spacing out the linear layouts/textviews

I want to thank you all in advance for helping me out on this (and so many other) issues.

Sincerely,

Reid

  • 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-05-27T15:50:12+00:00Added an answer on May 27, 2026 at 3:50 pm

    Solution is simple. You need to use android:stretchColumns attribute.
    Translate following example to your code

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    
    
    <TableLayout
    android:id="@+id/monthView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="0,1,2,3,4,5">
    
    </TableLayout>
    </LinearLayout>
    

    Java code

    public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        getView();
    }
    
    
        public TextView[] populateDays(int startDay) {
        TextView[] daysTextViewArr = new TextView[7]; 
        String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday",
                "Thursday", "Friday", "Saturday" }; 
        for (int i = 0; i < 7; i++) {
            daysTextViewArr[i] = new TextView(this);
            int day = i + startDay;
            if (day > 6) {
                day = day - 7;
            }
            daysTextViewArr[i].setText(days[i]);
        }
    
        return daysTextViewArr;
    }
    
    public void getView() {
        TableRow[] tableRows = new TableRow[6];
    
        TextView[] days = new TextView[7];
        days = populateDays(0);
        TableLayout monthView = (TableLayout) findViewById(R.id.monthView);
        LinearLayout headerLayout = new LinearLayout(this);
        headerLayout.setBackgroundColor(Color.WHITE);
        LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT, 1f); // create the
    
        for (int i = 0; i < 6; i++) {
            tableRows[i] = new TableRow(this);
    
        }
        for (int i = 0; i < 6; i++) {
            tableRows[0].addView(days[i]);
        }
    
        monthView.setBackgroundColor(Color.BLUE);
    
        for (int i = 0; i < 6; i++) {
            monthView.addView(tableRows[i]);
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a few problems re-writing flat links using htaccess, I have two
Using the new Rhino Mocks 3.5 Arrange/Act/Assert (AAA) Testing style, I'm having problems writing
I've been having problems writing XML and reading it in. I have a handwritten
I'm having problems with this getopt() code in a script that I'm writing which
I'm writing code for RegistrationScreen (blackberry mobile app) and i am having problems with
I am writing c++ code for a telnet client. I am having problems getting
I am having some problems writing to a file in unicode inside my c
I'm writing a C program but I keep having problems with my array of
I'm having a problem writing Norwegian characters into an XML file using C#. I
Having problems with a small awk script, Im trying to choose the newest of

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.