Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <pre><code>Layout:- </code></pre> </blockquote> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_marginBottom="154dp" android:layout_marginLeft="42dp" android:text="Total" android:textColor="#000000" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/textView1" android:layout_alignBottom="@+id/textView1" android:layout_alignParentRight="true" android:layout_marginRight="80dp" android:text="TextView" android:textColor="#000000" /&gt; &lt;TableLayout android:id="@+id/tableprovision" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="74dp" &gt; &lt;/TableLayout&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginTop="33dp" android:text="Expenses " android:textColor="#000000" android:textSize="18sp" /&gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@+id/textView3" android:layout_marginRight="30dp" android:text="Add" /&gt; &lt;/RelativeLayout&gt; </code></pre> <blockquote> <p>After creating Layout Then First You need to retrieve the json data then store it in the String[] assign the values to the table according to your requirement.For example go through the following.</p> <p>Activity :-</p> </blockquote> <pre><code>public class ProvisionActivity extends Activity { private TableLayout mTable; private static int sCount = 0; Button btnAdd; String[] pnames = { "provision1", "provision2", "provision3", "provision4", "provision5" }; String[] pprice = { "45", "85", "125", "15", "198" }; StringBuffer xpenses; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnAdd = (Button) findViewById(R.id.button1); mTable = (TableLayout) findViewById(R.id.tableprovision); xpenses = new StringBuffer(); btnAdd.setOnClickListener(new OnClickListener() { public void onClick(View v) { mTable.addView(addRow(pnames, pprice)); for (int i = 0; i &lt; mTable.getChildCount(); i++) { mTable.getChildAt(i); System.out.println("Table Row values are " + mTable.getChildAt(i)); xpenses = xpenses.append(mTable.getChildAt(i).toString()); System.out .println("Expense Table Values Are After Storing it in a String variable " + xpenses); } } }); } private TableRow addRow(String[] sname, final String[] sprice) { TableRow tr = new TableRow(this); tr.setId(1000 + sCount); tr.setLayoutParams(new TableLayout.LayoutParams( TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT)); TableRow.LayoutParams blparams = new TableRow.LayoutParams(150, 35); final Spinner spinner = new Spinner(this); spinner.setLayoutParams(blparams); spinner.setBackgroundColor(Color.DKGRAY); ArrayAdapter&lt;String&gt; xtypeadapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_dropdown_item, sname); spinner.setAdapter(xtypeadapter); tr.addView(spinner); TableRow.LayoutParams tlparams = new TableRow.LayoutParams(55, TableLayout.LayoutParams.WRAP_CONTENT); final TextView textView = new TextView(this); textView.setLayoutParams(tlparams); textView.setTextColor(Color.BLACK); spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { textView.setText(" " + sprice[spinner.getSelectedItemPosition()]); } public void onNothingSelected(AdapterView&lt;?&gt; arg0) { } }); tr.addView(textView); TableRow.LayoutParams blparams1 = new TableRow.LayoutParams( TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); final Button button = new Button(this); button.setLayoutParams(blparams1); button.setBackgroundColor(Color.LTGRAY); button.setText(" - "); button.setId(2000 + sCount); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { mTable.removeView(findViewById(v.getId() - 1000)); } }); tr.addView(button); sCount++; return tr; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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