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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:28:27+00:00 2026-06-15T17:28:27+00:00

I have seven equal Buttons in LinearLayout <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=wrap_content android:layout_height=wrap_content

  • 0

I have seven equal Buttons in LinearLayout

<?xml version="1.0" encoding="utf-8"?>    
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:weightSum="7" >

<Button
    android:id="@+id/btn_mon"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_weight="1"
    android:background="@color/white"        
    android:text="0" />

<Button
    android:id="@+id/btn_tus"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="0"
    android:background="@color/white"        
    android:layout_weight="1"/>
<Button
    android:id="@+id/btn_wen"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="0"
    android:background="@color/white"        
    android:layout_weight="1"/>
<Button
    android:id="@+id/btn_thu"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="0"
    android:background="@color/white"        
    android:layout_weight="1"/>
<Button
    android:id="@+id/btn_fri"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="0"
    android:background="@color/white"        
    android:layout_weight="1"/>
<Button
    android:id="@+id/btn_sat"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="0"
    android:background="@color/white"        
    android:layout_weight="1"/>
<Button
    android:id="@+id/btn_sun"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:text="0"
    android:background="@color/white"       
    android:layout_weight="1"/>
</LinearLayout>

Their OnClickListener is also equal (and initializing too):

if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.calendar_row, null);
            }

final Button btn_mon = (Button)convertView.findViewById(R.id.btn_mon);
final Button btn_tus = (Button)convertView.findViewById(R.id.btn_tus);
final Button btn_wen = (Button)convertView.findViewById(R.id.btn_wen);
final Button btn_thu = (Button)convertView.findViewById(R.id.btn_thu);
final Button btn_fri = (Button)convertView.findViewById(R.id.btn_fri);
final Button btn_sat = (Button)convertView.findViewById(R.id.btn_sat);
final Button btn_sun = (Button)convertView.findViewById(R.id.btn_sun);

        btn_mon.setOnClickListener(new View.OnClickListener() {             
            public void onClick(View v) { onCalBtnClick(btn_mon, weekdays.get(0).data); }});
        btn_tus.setOnClickListener(new View.OnClickListener() {             
            public void onClick(View v) { onCalBtnClick(btn_tus, weekdays.get(1).data); }});
        btn_wen.setOnClickListener(new View.OnClickListener() {             
            public void onClick(View v) { onCalBtnClick(btn_wen, weekdays.get(2).data); }});
        btn_thu.setOnClickListener(new View.OnClickListener() {             
            public void onClick(View v) { onCalBtnClick(btn_thu, weekdays.get(3).data); }});
        btn_fri.setOnClickListener(new View.OnClickListener() {             
            public void onClick(View v) { onCalBtnClick(btn_fri, weekdays.get(4).data); }});
        btn_sat.setOnClickListener(new View.OnClickListener() {             
            public void onClick(View v) { onCalBtnClick(btn_sat, weekdays.get(5).data); }});
        btn_sun.setOnClickListener(new View.OnClickListener() {             
            public void onClick(View v) { onCalBtnClick(btn_sun, weekdays.get(6).data); }});

onCalBtnClick method:

private void onCalBtnClick(Button btn, int day){            

            Log.d("debug", String.valueOf(day));
            btn.setTextColor(mContext.getResources().getColor(R.color.orange));
            //selectedYear, month are global
            Intent intent = new Intent();
            intent.putExtra("year", selectedYear);
            intent.putExtra("month", month);
            intent.putExtra("day", day);
            setResult(RESULT_OK, intent);
            finish();
        }

However, if I put Log.d into onCalBtnClick method (it is called from each clicklistener), only middle three buttons work. Two buttons from left side (btn_mon, btn_tus) and two buttons from right side (btn_sat, btn_sun) don’t react on user click. Middle buttons work fine.

This is similar question Android LinearLayout make button doesn’t work but my layout file corresponds to pattern in the answer there and buttons don’t work nevertheless

UPDATE

When I removed fixed button height and width in layout file (from 50dp to wrap_content), all buttons started to work!

However, now it doesn’t look as needed. There’s space needed between text’s on buttons.

And main question: WHY?

  • 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-15T17:28:28+00:00Added an answer on June 15, 2026 at 5:28 pm

    If you using weights in your layout, you are telling that it should be filled with some objects with some proportions. It just opposite to “wrap_content”. With weights outer layout defines size of inner views, while “wrap_content” means that outer layout size is defined by inner views.
    Please decide what approach is better in that case – removing weights or fixed inner views sizes.

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

Sidebar

Related Questions

I have seven strings in a program named string1 through string7. The size of
I have seven words in the array: string[7] = {x,x,x,x,x,x,x}; the x is generated
How would I create a DecimalFormat that would only have seven digits total and
I am having a HTML table with many rows. I have seven columns in
I have never programmed a gadget for Vista or Seven, but I would like
Suppose I have a string like this: one two three four five six seven
I have written my program in python. It is written across seven files and
I have seen SQL that uses both != and <> for not equal .
I have a table and I would like to set a variable equal to
I have seen this in a lot of XML comments for classes in the

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.