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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:46:57+00:00 2026-06-07T22:46:57+00:00

I have a custom control which is supposed to work like the Segmenttab controller

  • 0

I have a custom control which is supposed to work like the Segmenttab controller in iOS.

It has 3 textviews and the layout is as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/groupofthree"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/background"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tv_1"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@color/black"
        android:gravity="center"
        android:text="Retiree"
        android:textColor="@color/whitetext"
        android:textSize="15dp"
        android:textStyle="normal" />

    <TextView
        android:id="@+id/tv_2"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@color/lightGrey"
        android:gravity="center"
        android:padding="3dp"
        android:text="Under18/fulltime"
        android:textColor="@color/whitetext"
        android:textSize="15dp"
        android:textStyle="normal" />

    <TextView
        android:id="@+id/tv_3"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:background="@color/black"
        android:gravity="center"
        android:text="Others"
        android:textColor="@color/whitetext"
        android:textSize="15dp"
        android:textStyle="normal" />

</LinearLayout>

The control looks like this:

    public class SegmentedRadioGroup extends View{

        private Context m_Context;

        public TextView tv1;
        public TextView tv2;
        public TextView tv3;
        int selectedIndex = 0;

        public SegmentedRadioGroup(Context context, AttributeSet attrs) {

            super(context, attrs);
            m_Context = context;

        }

        public SegmentedRadioGroup(Context context, AttributeSet attrs, int defStyle) {

            super(context, attrs, defStyle);
        }

        public SegmentedRadioGroup(Context context) {
            super(context);
            // TODO Auto-generated constructor stub

            m_Context = context;
            LayoutInflater inflater = (LayoutInflater) m_Context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v = inflater.inflate(R.layout.threeradiobutton, null);


            v.isInEditMode();
            tv1 = (TextView) v.findViewById(R.id.tv_1);
            tv2 = (TextView) v.findViewById(R.id.tv_2);
            tv3 = (TextView) v.findViewById(R.id.tv_3);

            tv1.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                    selectedIndex = 0;
                    tv1.setBackgroundColor(R.color.darkgrey);
                    tv2.setBackgroundColor(R.color.lightGrey);
                    tv3.setBackgroundColor(R.color.lightGrey);
                }
            });

            tv2.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    selectedIndex = 1;
                    tv1.setBackgroundColor(R.color.lightGrey);
                    tv2.setBackgroundColor(R.color.darkgrey);
                    tv3.setBackgroundColor(R.color.lightGrey);

                }
            });

            tv3.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    selectedIndex = 2;

                    tv1.setBackgroundColor(R.color.lightGrey);
                    tv2.setBackgroundColor(R.color.lightGrey);
                    tv3.setBackgroundColor(R.color.darkgrey);
                }
            });
        }

        @Override
        protected void onDraw(Canvas canvas) {
            // TODO Auto-generated method stub
            super.onDraw(canvas);


        }


    }

The activity in which i add this custom view to the layout is as follows:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/background"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/widget1216"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/appspecific_menubar" >

            <TextView
                android:id="@+id/widget1222"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:text="@string/transaction_accounts_topbar"
                android:textColor="@color/whitetext"
                android:textSize="18sp"
                android:textStyle="bold" >
            </TextView>

            <ImageButton
                android:id="@+id/home_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:background="@null"
                android:paddingBottom="5dip"
                android:paddingLeft="10dip"
                android:paddingTop="5dip"
                android:src="@drawable/home" >
            </ImageButton>
        </RelativeLayout>
    <LinearLayout 
        android:id="@+id/testLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" />.
     </LinearLayout>

And the activity looks like this. I have added the view into the layout using addview.

    public class TransactionAccount extends Activity {
        LinearLayout selector;
        SegmentedRadioGroup sg_test;
        LayoutInflater inflater;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.transactionaccount_main);
            selector = (LinearLayout)findViewById(R.id.testLayout);




            sg_test = new SegmentedRadioGroup(this);
            selector.addView(sg_test);



    //      inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //      selector = inflater.inflate(R.id., null);

    //      sg_test = new SegmentedRadioGroup(this);

    //      sg_test.tv1.setText("1");
    //      sg_test.tv2.setText("2");
    //      sg_test.tv3.setText("3");
    //      sg_test.tv1.setBackgroundColor(R.color.blacktext);
    //      sg_test.setVisibility(View.VISIBLE);
    //      
    //      Log.d("TransactionAccount", "onCreate++++++" + sg_test.tv1.getText());
    //      Log.d("TransactionAccount", "onCreate++++++" + sg_test.tv2.getText());
    //      Log.d("TransactionAccount", "onCreate++++++" + sg_test.tv3.getText());
        }
    }

But what i see on the screen is a blank screen.. and not the custom control which should show up. Kindly tell me where am i going wrong.

Thanks in advance.

  • 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-07T22:46:58+00:00Added an answer on June 7, 2026 at 10:46 pm

    First of all, you can’t add child Views to a subclass of View because it doesn’t have the addView method. Instead, you should extend ViewGroup or one of its subclasses(like LinearLayout, RelativeLayout etc).

    After you do the above thing you can simple add the Views with:

    View v = inflater.inflate(R.layout.threeradiobutton, this, true);
    

    to actually add the inflated layout to the custom View.

    Right now you don’t see something on the screen because there isn’t something to see, your custom View is empty.

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

Sidebar

Related Questions

I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have a custom control which has a property of type Collection<System.Drawing.Point> . When
I have a custom control which contains a Repeater control. The Repeater has an
I have a custom user control which has some textboxes and some buttons. In
I have a custom control's library. Now there's a control which looks like a
I'm currently writing an custom control which has to hold child control and have
I have a custom control which has a RadioButtonList control in it. On selecting
I have custom control like tabbar which displays many controllers some of them also
I have a custom control which displays results of some operations. It is hidden
I have a custom server control which wraps a RadEditor (basically a textarea). I

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.