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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:55:00+00:00 2026-06-15T20:55:00+00:00

I have written activities which used layouts which are entirely defined by xml, e.g:

  • 0

I have written activities which used layouts which are entirely defined by xml, e.g:

setContentView(R.layout.my_layout_defined_by_xml);

I have also written activities which used layouts which are created entirely programatically, e.g.:

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

    game_frame_layout = new FrameLayout(getApplicationContext());

    game_frame_layout.addView(some_view_I_made);

    setContentView(game_frame_layout);

But what I have never done, and don’t know how to do, is combine the two (can this even be done?) For example, say I want to have the whole screen filled with buttons and views defined in xml, but wish to programmatically add an extra button somewhere. Or conversely I may wish to have a programatically created layout include a sub-layout defined by xml.

I suspect it may actually be quite trivial, but one problem is that I don’t know how to translate a layoutResID, (like R.id.my_layout_defined_by_xml) into a layout.

  • 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-15T20:55:01+00:00Added an answer on June 15, 2026 at 8:55 pm

    you can create a View object from an xml file like that:

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

    and the other way around:
    you can create a class that extends View, for example MyTextView, and when you want to include it in your xml files you do it like that:

    <com.example.mypackage.MyTextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="false" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written below code doing below activities I created one transaction using Spring
have written this little class, which generates a UUID every time an object of
I have written a bash script which installs a number of packages, however for
I have written a raw binary image file into a buffer which is an
I have android application that is written regular way. layouts, java, APK. Now, depending
In my application I have many classes and activities. Droid is a class which
I have created an application which needs 'hand-over' to the support group in the
I would like to call one of the activities that I have written in
I have written a mapping application which can either use Google Maps or Open
I have the following data in an XML file which i am reading using

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.