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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:46:41+00:00 2026-06-11T02:46:41+00:00

I created a LinearLayout in java code, but I don’t know how to add

  • 0

I created a LinearLayout in java code, but I don’t know how to add an image background.

This is the code I have for the LinearLayout:

LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(1);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /** Create a new layout to display the view */
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(1); 

    TextView variacion[];

     try {

        /** Handling XML */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();

        /** Send URL to parse XML Tags */
        URL sourceUrl = new URL("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=75");

        /** Create handler to handle XML Tags ( extends DefaultHandler ) */
        MyXMLHandler myXMLHandler = new MyXMLHandler();
        xr.setContentHandler(myXMLHandler);
        xr.parse(new InputSource(sourceUrl.openStream()));

        } catch (Exception e) {
            System.out.println("XML Pasing Excpetion = " + e);
        }

    /** Get result from MyXMLHandler SitlesList Object */
    sitesList = MyXMLHandler.sitesList;

    /** Assign textview array lenght by arraylist size */
    registro = new TextView[sitesList.getRegistro().size()];
//    nemotecnico = new TextView[sitesList.getNemotecnico().size()];
    variacion = new TextView[sitesList.getVariacion().size()];

   //category = new TextView[sitesList.getName().size()];

    /** Set the result text in textview and add it to layout */
    for (int i = 0; i < sitesList.getRegistro().size(); i++) {

        variacion[i] = new TextView(this);
        variacion[i].setText(sitesList.getVariacion().get(i));



        Pattern pattern = Pattern.compile("^\\+?[0-9]+([,\\.][0-9]*)?$");
        Matcher matcher = pattern.matcher(sitesList.getVariacion().get(i));
        if (!matcher.matches())

        variacion[i].setTextColor(Color.parseColor("#ff0000"));
        else
        variacion[i].setTextColor(Color.parseColor("#008000")); 


       layout.addView(variacion[i]);
    }   
    /** Set the layout view to display */
   setContentView(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-11T02:46:42+00:00Added an answer on June 11, 2026 at 2:46 am

    Use:

     LinearLayout layout = new LinearLayout(this);
     layout.setOrientation(1);
     layout.setBackgroundResource(R.drawable.background);
    

    Where background is your background image in res folder.

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

Sidebar

Related Questions

If I have a page whose layout is designated by XML code, but I
I have create a Java class extending LinearLayout as shown below public class CustomLinear
I have create a Java class extending LinearLayout as shown below public class News
I created one linear layout and I have added two relative layout. I wish
Take the following code: ImageView imageView = new ImageView(activity); imageView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); Running this
Following on from another question I have asked I have created a new class
I have created an app in which I had use SPenSDK to create image
I made this code in Eclipse (for Android), but there are some errors .
I have a problem: Java Code public class VisualizzaListaActivity extends TabActivity { /** Called
Can we Manipulate the Xml layout in our Java code . I mean Lets

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.