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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:40:50+00:00 2026-05-26T15:40:50+00:00

I’m making a custom XML layout to display a cocktail recipe. Here is my

  • 0

I’m making a custom XML layout to display a cocktail recipe. Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:id="@+id/drinkname" android:layout_height="wrap_content"
    android:textSize="30sp" android:text="@string/drink_name"
    android:layout_width="wrap_content" android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<TextView android:layout_width="fill_parent"
    android:layout_height="2dp" android:background="#FFFFFFFF"
    android:layout_below="@id/drinkname" />

<TextView android:layout_height="wrap_content" android:id="@+id/ingredient_label"
    android:text="Ingredients: " android:layout_width="wrap_content"
    android:layout_below="@+id/drinkname" android:layout_marginLeft="10dp"
    android:layout_marginTop="16dp" />
<TableLayout android:layout_height="wrap_content"
    android:id="@+id/ingredient_table" android:layout_width="wrap_content"
    android:layout_alignTop="@+id/ingredient_label"
    android:layout_alignLeft="@+id/drinkname"
    android:layout_alignParentRight="true">
    <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <TextView android:text="• 2 oz. Gin (Boodles)"android:id="@+id/textView1"
        android:layout_width="wrap_content" 
                android:layout_height="wrap_content" />
    </TableRow>
    <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView android:text="• 2 oz. Vodka (Stolichnaya)"
            android:id="@+id/textView2" android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </TableRow>
    <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView android:text="• 1/2 oz. Vermouth, dry" android:id="@+id/textView3"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </TableRow>
    <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView android:text="• 3 pieces Olive" android:id="@+id/textView4"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </TableRow>
</TableLayout>

<TextView android:id="@+id/instruction_label"
    android:layout_height="wrap_content" android:layout_width="wrap_content"
    android:layout_below="@id/ingredient_table" android:layout_alignLeft="@id/ingredient_label"
    android:text="Instructions: " android:layout_marginTop="25dp" />
<TextView android:id="@+id/instructions"
    android:layout_height="wrap_content" android:layout_width="wrap_content"
    android:layout_alignTop="@id/instruction_label"
    android:layout_alignLeft="@id/drinkname"
    android:layout_alignParentRight="true" android:text="@string/drink_instructions" />

<TextView android:id="@+id/glass_label" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:layout_below="@id/instructions"
    android:layout_alignLeft="@id/ingredient_label" android:text="Glass:"
    android:layout_marginTop="25dp" />
<TextView android:id="@+id/glass_type"
    android:layout_toRightOf="@id/glass_label" android:text="@string/drink_glass"
    android:layout_height="wrap_content" android:layout_width="wrap_content"
    android:layout_alignTop="@id/glass_label" android:layout_alignLeft="@+id/drinkname" />

As you can see all the content displayed is written into the layout itself or is taken from a string resource. My question is: what would I have to do to keep the layout I created below, but be able to fill in the content programmatically?

  • 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-26T15:40:50+00:00Added an answer on May 26, 2026 at 3:40 pm

    You would have to do something like this…

    (TextView) this.findViewById(R.id.drinkname).setText("Water");
    

    Use findView to get a reference to a particular view on the activity. Pass it the Resource identifier you gave in the XML (the id property). Cast it to the correct View type, and then set it’s properties.

    The resource id’s are created automatically from the id attribute in XML, and added to the R class inside R.id..

    As an example from the application I’m currently writing, I usually define the views I’m going to be modifying as class level fields near the beginning of the class like so:

    TextView tvGameDate;
    TextView tvGameTime;
    TextView tvHomeTeam;
    TextView tvAwayTeam;
    TextView tvHomePitcher;
    

    Then near the start of onCreate I will populate them all with the references to the actial views like this:

    tvGameDate = (TextView) this.findViewById(R.id.tvGameDate);
    tvGameTime = (TextView) this.findViewById(R.id.tvGameTime);
    tvHomeTeam = (TextView) this.findViewById(R.id.tvHomeTeam);
    tvAwayTeam = (TextView) this.findViewById(R.id.tvAwayTeam);
    tvHomePitcher = (TextView) this.findViewById(R.id.tvHomePitcher);
    

    Then I can just refer to the fields I defined whenever I need to access them like this:

    tvHomeTeam.setText(attributes.getNamedItem("home_long").getNodeValue());
    tvHomePitcher.setText(" (" + attributes.getNamedItem("home_pitcher").getNodeValue() + ")");
    

    In your XML it looks like you may actually need to dynamically create additional text views on the fly based on the recipe. You can do this like so (where llIngredients maps to some LinearLayout in your XML):

    TextView tv = new TextView(context);
    
    tv.setTextColor(Color.BLACK);
    tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tv.setText("Some text for the new view");
    llIngredients.addView(tv);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm making a simple page using Google Maps API 3. My first. One marker

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.