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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:29:30+00:00 2026-05-13T16:29:30+00:00

I am still pretty new to Android development, and I have not been able

  • 0

I am still pretty new to Android development, and I have not been able to find any examples of how to do this.

In my Activity, I use “setContextView(new myViewClass)” to designate a View-extended class as the one to load. Everything works fine in terms of loading the view, where I create various elements (LinearLayouts, buttons, etc.) based on a number of conditions. Unfortunately, I cannot get any of these elements to actually appear on the screen.

I guess my question goes to a greater understanding of Views. All of the examples I’ve seen concern setting an xml file as the base view and then altering it within the code. Is there some alternative to this?

Thanks.

Here is an example code I’ve been trying to make work. There are other things going on, but this is the relevant info. For program context, this class is substantiated with the setContextView(new createView(this)):

public createView(Context c){
    super(c);

    // Create a simple layout
    LinearLayout layout = new LinearLayout(top.getContext());
    layout.setOrientation(LinearLayout.VERTICAL);


    // Create test text
    TextView mTestText = new TextView(c);
    mTestText.setText("This is a test");

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(10, 10, 10, 10);
    layout.addView(mTestText, lp);
}
  • 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-13T16:29:31+00:00Added an answer on May 13, 2026 at 4:29 pm

    I think the problem is that you are not adding the layout to your CreateView. However, the View class does not have an add method (see http://developer.android.com/reference/android/view/View.html).

    Since LinearLayout is the base view for your extended view, you could extend LinearLayout instead and add the TextView to your extended class. If you do this, your CreateView class would probably look something like this:

    /**
     * Since the LinearLayout is the base layout, we'll extend it.
     */
    public class CreateView extends LinearLayout {
        public CreateView(Context context) {
            super(context);
            setOrientation(LinearLayout.VERTICAL);
    
            TextView mTestText = new TextView(context);
            mTestText.setText("This is a test");
    
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(10, 10, 10, 10);
            addView(mTestText, lp);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.