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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:55:22+00:00 2026-05-24T12:55:22+00:00

I created a compound control using xml, and am able to re-use it by

  • 0

I created a compound control using xml, and am able to re-use it by placing in other xml
layouts. But i want to add it at runtime using java code. I tried the following code but only the textview is visible and the compound-control is not shown…

I am quiet new to android so would appreciate any help or suggestions..

COMPOUND – CONTROL LAYOUT

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout   xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/border_lines"

>
    <TextView android:id="@+id/msg_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="SAMPLE MESSAGE TITLE"
    />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    >
        <Button android:id="@+id/btn_shw"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="SHOW MSG"
            android:layout_weight="1"
        />
        <Button android:id="@+id/btn_dis"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text=" DISABLE"
            android:layout_weight="1"
        />
        <Button android:id="@+id/btn_del"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text=" DELETE "
            android:layout_weight="1"
        />
    </LinearLayout>    
</LinearLayout>

COMPOUND-CONTROL CODE

public class RemainderControl extends LinearLayout
{
    Button btn1,btn2,btn3;
    TextView tv1;
    public RemainderControl(Context context)
    {
        super(context);
            LayoutInflater inflater=LayoutInflater.from(context);
        inflater.inflate(R.layout.remainder_control,this);

        loadviews();
    }

    public RemainderControl(Context context,AttributeSet attrs)
    {
        super(context,attrs);

        LayoutInflater inflater=LayoutInflater.from(context);
        inflater.inflate(R.layout.remainder_control,this);

        loadviews();


    }

    private void loadviews()
    {
        btn1=(Button)findViewById(R.id.btn_shw);
        btn2=(Button)findViewById(R.id.btn_dis);
        btn3=(Button)findViewById(R.id.btn_del);
        tv1=(TextView)findViewById(R.id.msg_title);
            btn1.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                tv1.setText("SHOW BUTTON PRESSED");     
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                tv1.setText("DISABLE BUTTON PRESSED");      
            }
        });
        btn3.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                tv1.setText("DELETE BUTTON PRESSED");
            }
        });
        tv1.setOnClickListener(new View.OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {
                tv1.setText("");
            }
        });
    }
}

CODE TO ADD CONTROL

public class RemainderList extends Activity 
{
    ScrollView sv1;
    LinearLayout ll1;
    deepak.android.remainder.RemainderControl rc1;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        int ht=LayoutParams.WRAP_CONTENT;
        int wt=LayoutParams.FILL_PARENT;

        sv1=new ScrollView(this);
        ll1=new LinearLayout(this);
        ll1.setOrientation(LinearLayout.VERTICAL);
        sv1.addView(ll1);

        TextView tv1=new TextView(this);
        tv1.setText("THIS IS SAMPLE TEXT");
        ll1.addView(tv1,new LinearLayout.LayoutParams(wt,ht));

        rc1=new deepak.android.remainder.RemainderControl(this);
        ll1.addView(rc1,new LinearLayout.LayoutParams(wt,ht));

        setContentView(sv1);
    }
}
  • 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-24T12:55:23+00:00Added an answer on May 24, 2026 at 12:55 pm

    When your control is included in xml, public RemainderControl(Context context,AttributeSet attrs) constructor is invoked. But in your code you directly invoke constructor public RemainderControl(Context context). Move all your code that inflates the layout and sets the listeners into some method (for example init()) and call it in both constructors.

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

Sidebar

Related Questions

I created a Compound Control that is added at runtime from an activity, but
I have created a compound control that I am reusing in multiple activities. This
I tried to use compound conditions in the correlated subquery, but it didn't return
I'm trying to build a compound control in Android, containing (among other things) a
I have to create a custom compound button bar control in Android like the
I want to create a component that allows us to have compound keyboard shortcuts
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a few mediawiki custom tags, using the guide found here http://www.mediawiki.org/wiki/Manual:Tag_extensions I
I created an Interop user control in VS2005. When the user control is shown
when using compound pk, can insertion of values be the same ? I illustrate

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.