Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Alrighty here we go. Keep in mind, this is done after a HTTP Request, so it's implementing an Async Task, I just left out that bit as it isn't relevant to the question I had.</p> <p>First, create 3 lists of things. 1 List of layouts (the outer div like container), 1 list of text views, and 1 list of imageviews. For my example, I looped through a list of my own class called business:</p> <pre><code> private List&lt;RelativeLayout&gt; layoutContainers = new ArrayList&lt;RelativeLayout&gt;(); private List&lt;TextView&gt; textContainers = new ArrayList&lt;TextView&gt;(); private List&lt;ImageView&gt; imageContainers = new ArrayList&lt;ImageView&gt;(); .... @Override protected void onPostExecute(List&lt;Business&gt; blist){ for(int i=0;i&lt;blist.size();i++){ RelativeLayout newLayout = new RelativeLayout(mContext); TextView tv = new TextView(mContext); ImageView iv = new ImageView(mContext); //// or getApplicationContext() tv.setId(1); iv.setId(2); newLayout.addView(tv); newLayout.addView(iv); icons_row.addView(newLayout); // this is another relative layout created via XML as standard RelativeLayout.LayoutParams layoutParms = (RelativeLayout.LayoutParams)newLayout.getLayoutParams(); RelativeLayout.LayoutParams textParms = (RelativeLayout.LayoutParams)tv.getLayoutParams(); RelativeLayout.LayoutParams imageParms = (RelativeLayout.LayoutParams)iv.getLayoutParams(); layoutParms.height = RelativeLayout.LayoutParams.MATCH_PARENT; layoutParms.width = 175; newLayout.setGravity(Gravity.CENTER_VERTICAL); // Text Styling textParms.height = RelativeLayout.LayoutParams.WRAP_CONTENT; textParms.width = RelativeLayout.LayoutParams.MATCH_PARENT; tv.setBackgroundColor(R.drawable.my_border); tv.setPadding(1, 5, 1, 2); tv.setTextColor(Color.GREEN); tv.setGravity(Gravity.CENTER_HORIZONTAL); // center text // Image Styling - background set deeper inside imageParms.addRule(RelativeLayout.BELOW, tv.getId()); imageParms.setMargins(35, 0, 0, 0); imageParms.height = RelativeLayout.LayoutParams.WRAP_CONTENT; imageParms.width = RelativeLayout.LayoutParams.WRAP_CONTENT; // set the params tv.setLayoutParams(textParms); iv.setLayoutParams(imageParms); newLayout.setLayoutParams(layoutParms); // add them to the lists (created above) textContainers.add(tv); imageContainers.add(iv); layoutContainers.add(newLayout); } bearingTextView = (TextView)findViewById(R.id.bearingTextView); gps.calculateBearing(compass, bearingTextView ,blist, textContainers, imageContainers,layoutContainers); } // end on Post Execute </code></pre> <hr> <p>I sent them through to my GPS which then sent them to my Compass. To make changes to them, for example, update the text, you do the following... Taking for example, the calculateBearing method stated above... Ignoring the other values, just the Containers.</p> <hr> <pre><code>public class Gps{ private List&lt;TextView&gt; textContainers; private List&lt;ImageView&gt; imageContainers; private List&lt;RelativeLayout&gt; layoutContainers; ... public void calculateBearing(Compass compass, TextView bearingText, List&lt;Business&gt; blist, List&lt;TextView&gt; textContainers,List&lt;ImageView&gt; imageContainers,List&lt;RelativeLayout&gt; layoutContainers){ this.textContainers = textContainers; this.imageContainers = imageContainers; this.layoutContainers = layoutContainers; //eg. change the text for(int i=0; i&lt;textContainers.size(); i++){ textContainers.get(i).setText("This is text field: " + Integer.toString(i)); // will return, 1,2,3 etc depending on whatever textField is there } } } </code></pre> <p>Keep in mind that I call these external methods from onPostExecute, so the UI will be updated. If I wasn't clear on anything let me know</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload