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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:53:55+00:00 2026-06-04T00:53:55+00:00

Sorry if I ask silly question, but so far had no luck in figuring

  • 0

Sorry if I ask silly question, but so far had no luck in figuring out this one. I have form with 2 radio buttons that decide layout and used components of layout bellow them. Here is one of the layouts

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
    <TextView
            android:id="@+id/arrival_date_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/arrival_date_label"/>
    <EditText
            android:id="@+id/arrival_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/arrival_date_label"
            android:hint="10/05/2012"/>
    <Spinner
            android:id="@+id/arrival_time_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/arrival_date"/>
    <TextView
            android:id="@+id/return_date_label"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/return_date_label"
            android:layout_below="@id/arrival_time_spinner"/>
    <EditText
            android:id="@+id/return_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/return_date_label"
            android:hint="10/05/2012"/>
    <Spinner
            android:id="@+id/return_time_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/return_date"/>
</RelativeLayout>

and Java class to initialize some of the components used


public class ReturnFixedDays extends RelativeLayout {
    private EditText arrivalDate;
    private Spinner arrivalTime;
    private EditText returnDate;
    private Spinner returnTime;
    private final String pattern = "dd/MM/yyyy";

    public ReturnFixedDays(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.return_fixed_days, null);

        arrivalDate = (EditText) view.findViewById(R.id.arrival_date);
        arrivalDate.setText(arrivalDate());

        arrivalTime = (Spinner) view.findViewById(R.id.arrival_time_spinner);
        ArrayAdapter adapter = new ArrayAdapter(context, R.array.travel_time_entries,android.R.layout.simple_spinner_item);
        arrivalTime.setAdapter(adapter);

        returnDate = (EditText) view.findViewById(R.id.return_date);
        returnDate.setText(returnDate());

        returnTime = (Spinner) view.findViewById(R.id.return_time_spinner);
        ArrayAdapter adapter2 = new ArrayAdapter(context, R.array.travel_time_entries,android.R.layout.simple_spinner_item);
        returnTime.setAdapter(adapter2);
    }

    private String arrivalDate(){
        return dateToString(today());
    }

    private String returnDate(){
        return dateToString(weekLater());
    }

    private String dateToString(Date date){
        return formatter().format(date);
    }

    private SimpleDateFormat formatter(){
        return new SimpleDateFormat(pattern);
    }

    private Date weekLater(){
        return adjustDateBy(today(), 7);
    }

    private Date today(){
        return Calendar.getInstance().getTime();
    }

    private Date adjustDateBy(Date currentDate, int numOfDays) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        calendar.add(Calendar.DATE, numOfDays);

        return calendar.getTime();

    }

}

Now to add this layout to view I do as following in xml

<RelativeLayout
            android:id="@+id/dates_layout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/flight_layout">
        <TextView
                android:id="@+id/date_label"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="@string/dates_label"
                style="@style/Label"/>
        <RadioGroup
                android:id="@+id/dates_radio_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_below="@id/date_label">
            <RadioButton
                    android:id="@+id/flexible_dates_radio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/flexible_dates_label"
                    style="@style/Label"/>
            <RadioButton
                    android:id="@+id/fixed_dates_radio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:checked="true"
                    android:text="@string/fixed_dates_label"
                    style="@style/Label"/>
        </RadioGroup>
    </RelativeLayout>
    <RelativeLayout
            android:id="@+id/stub_container"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/dates_layout">

        <com.flyweekend.android.date.view.ReturnFixedDays
                android:id="@+id/return_fixed_days_stub"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout="@layout/return_fixed_days"/>

        <com.flyweekend.android.date.view.ReturnFlexibleDays
                android:id="@+id/return_flexible_days_stub"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout="@layout/return_flexible_days"/>
    </RelativeLayout>

FlightView.java


@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        context = getActivity();
        dateTypeRadioGrp = dateTypeRadioGroup(view);
        returnFixedDays = (RelativeLayout) view.findViewById(R.id.return_fixed_days_stub);
        updateDatesVisibility();
        return view;
    }

private RadioGroup dateTypeRadioGroup(View view){
        RadioGroup group = (RadioGroup)view.findViewById(R.id.dates_radio_group);
        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup radioGroup, int selected) {
                if(selected == R.id.flexible_dates_radio){
                    Log.i(TAG, "Flexible dates selected");
                    updateDatesVisibility();
                }else{
                    Log.i(TAG, "Fixed dates selected");
                    updateDatesVisibility();
                }
            }
        });
        return group;
    }

    private void updateDatesVisibility(){
        if(dateTypeRadioGrp.getCheckedRadioButtonId() == R.id.fixed_dates_radio){
            returnFixedDays.setVisibility(View.VISIBLE);
        } else{
            returnFixedDays.setVisibility(View.INVISIBLE);
        }
    }

However neither group is ever visible. I guess I need extra pair of eyes to spot where I’m going wrong in adding these layouts dynamically.

  • 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-04T00:53:57+00:00Added an answer on June 4, 2026 at 12:53 am

    With this:

    View view = inflater.inflate(R.layout.return_fixed_days, null);
    

    you’ve just inflated a layout file, you didn’t actually attached it to your custom view ReturnFixedDays. To attach that inflated layout to your custom view you have to pass this as the second parameter(representing the parent of the newly inflated view hierarchy):

    View view = inflater.inflate(R.layout.return_fixed_days, this);
    

    There could be other things wrong in your code, so check and see if this solves your problem.

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

Sidebar

Related Questions

I am really sorry to ask this silly question. I have been onto this
Sorry to ask this question again but I tried several solutions on stackoverflow and
Sorry, this's my first time to ask a question here. So, I don't have
I'm really sorry to have to ask this, but I clearly don't understand something
I am sorry to ask this trivial question but I could not find a
I am using cakePHP 1.26. I am sorry to ask this question, but I
I am sorry to ask this question when it has already been asked but
Sorry to ask such a question, but I've spent 1/2 hour on this and
Sorry to ask this question, but it's now day 3 I try to solve
Sorry to ask a silly question, but I can't find a complete answer. With

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.