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 8454297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:59:21+00:00 2026-06-10T11:59:21+00:00

I have a string array which holds the names of the weekdays: private final

  • 0

I have a string array which holds the names of the weekdays:

private final String[] weekdays = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

I have set Monday as the first day of the week by default.

Now I have given the user the option to select if s/he wants to set either Sunday or Monday as the first day of the week:

if (firstDay == 0) {
    holder.txtWeekdays.setText(weekdays[position]);
 }

Using the same String array how do I set Sunday as the first day of the Week?

else {
     holder.txtWeekdays.setText(weekdays[position]-1);  //this returns an error 
}

UPDATED CODE:

public class CalendarWeekAdapter extends BaseAdapter{

private final String[] weekdays = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
Context mContext;

   private LayoutInflater mInflater;
   public CalendarWeekAdapter(Context c)
   {
          mContext=c;
          mInflater = LayoutInflater.from(c);
   }
   public int getCount()
   {
          return weekdays.length;
   }
   public Object getItem(int position)
   {
          return position;
   }
   public long getItemId(int position)
   {
          return position;
   }
   public View getView(int position, View convertView, ViewGroup parent)
   {
          ViewHolder holder=null;
          if(convertView==null)
          {
                 convertView = mInflater.inflate(R.layout.calendar_week_gridcell, parent,false);
                 holder = new ViewHolder();
                 holder.txtWeekdays=(TextView)convertView.findViewById(R.id.weekdays);
                 if(position==0)
                 {                             
                       convertView.setTag(holder);
                 }
          }
          else
          {
                 holder = (ViewHolder) convertView.getTag();
          }

          if (firstDay == 0) {
              holder.txtWeekdays.setText(weekdays[position]);
          }
          else {
              holder.txtWeekdays.setText(weekdays[position]); 
          }

          return convertView;
   }

}
static class ViewHolder
{        
      TextView txtWeekdays;                 
}
  • 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-10T11:59:22+00:00Added an answer on June 10, 2026 at 11:59 am

    You are trying to subtract 1 from a string. That’s not really going to work.

    What you need to do is create a method that returns the day of the week. Something like this:

    public String getDayOfWeek(int day, int firstDay) {
       String[] weekdays;
       if (firstDay == 0)
          weekdays = new String[]{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
       else
          weekdays = new String[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
       return weekdays[day];
    }
    

    Now, you COULD do this by position (using weekdays[position - 1]), but the above will help you avoid errors in your code (indexing -1 for example), and give you more clarity as to what is being returned.

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

Sidebar

Related Questions

I have a string array which holds the name of 500 stocks. Now i
I have a string array variable called 'myAttachmentArray[]' which holds different figures like this:
I have a string array selectCancel with setter and getter methods, which is a
I have a string say string s =C:\\Data , I have an array which
I have written an assembly in C# which returns a string array, the C#
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
I have this 4 Dimensional array to store String values which are used to
I have this: one string variable which holds the class name ( $classname )
I have an array of type string which I want to re-use inside a
I have an array which holds references to a bland base type, let's call

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.