android programatically adding text views to a relative layout

hi im trying to add text fields based on a JSON Feed i have a view that displays a result but i'm debating with myself should i create a text field in that layout and programmatically tell the text field how many lines there are and add line breaks or do i add a new text field to the view for each item in the feed.

heres what i want to acheive

info                     info
Team Name     1-3   Team Name
Scorer                 Scorer
                       Scorer
                       Scorer

heres my layout so far it has everything but the scorers

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:paddingBottom="30dp"
    android:paddingTop="10dp" >

    <TextView
        android:id="@+id/Division"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="18dp"
        android:layout_marginTop="5dp"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/HomeTeam"
        android:layout_width="115dp"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/Division"
        android:layout_below="@+id/Division"
        android:text="Medium Text"
     android:textSize="20dp"
        android:textColor="@color/blue" 
        android:ellipsize="end"
        android:lines="2"
        android:gravity="left"
        android:textStyle="bold"
        />

    <TextView
        android:id="@+id/Attendence"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/HomeTeam"
        android:layout_alignParentRight="true"
        android:layout_marginRight="18dp"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/AwayTeam"
        android:layout_width="115dp"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/Attendence"
        android:layout_below="@+id/Attendence"
        android:text="Medium Text"
     android:textSize="20dp"
        android:textColor="@color/blue"
        android:ellipsize="end"
        android:lines="2"
        android:gravity="right"
        android:textStyle="bold"
         />

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Attendence"
        android:layout_centerHorizontal="true"
        android:text="-"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/blue" />

    <TextView
        android:id="@+id/AwayScore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TextView02"
        android:layout_alignBottom="@+id/TextView02"
        android:layout_toRightOf="@+id/TextView02"
        android:text="0"
         android:textSize="20dp"
        android:textColor="@color/blue"
        android:layout_marginLeft="10dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/HomeScore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TextView02"
        android:layout_alignBottom="@+id/TextView02"
        android:layout_toLeftOf="@+id/TextView02"
        android:text="0"
        android:textSize="20dp"
        android:textColor="@color/blue" 
        android:layout_marginRight="10dp"
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/HomeScorers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/HomeTeam"
        android:layout_below="@+id/HomeTeam"

        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/AwayScorers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/AwayTeam"
        android:layout_below="@+id/AwayTeam"

        android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

2 Answers

  1. Leander- Reply

    2019-11-16

    Please Check out the link. Here Create relative layout Programatically. I think it Help you.

    Link

    thanks

  2. Lee- Reply

    2019-11-16

    • create a xml of a particular row (as create in list) Add a empty
    • List item linear layout/Table layout in Layout xml.
    • Inflate that row in java file as per json data in loop view
    • set the data as sets in list get function.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>