Hello. There is such code:

TextView NumbZK = (TextView)findViewById(R.id.editText2); final int Numb = Integer.parseInt(NumbZK.getText().toString()); TextView modN = (TextView)findViewById(R.id.editText1); final int N = Integer.parseInt(modN.getText().toString()); TableLayout table = (TableLayout) findViewById(R.id.tL1); TableRow tr = (TableRow) findViewById(R.id.tR1); TextView tv = (TextView) findViewById(R.id.field1); int[] mas = new int[N]; for (int i=0; i<N;i++){ mas[i]=(Numb%(i+1)); table.removeView(tr); tr.removeView(tv); tv.setText((i+1)+") "+(Numb%(i+1))); tr.addView(tv); table.addView(tr); } 

The idea is to add table rows dynamically in a loop. In the end, you should get something like this:

1) [Numb mod 1]
2) [Numb mod 2]
...
3) [Numb mod 20]

    1 answer 1

    Adapters are suitable in the case of a widget derived from AdapterView (ListView, GridView, Spinner, Gallery). The author uses TableLayout, which has nothing to do with adapters.

    For TableLayout, I can advise you to do this: create xml with single-line markup, leave TableLayout itself empty, and then in the right place in the code create an instance of the string using LayoutInflater and add it to TableLayout.

    To make it clearer, I will give an example.

    Activation markup res / layout / main.xml:

     <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/table" android:layout_width="fill_parent" android:layout_height="wrap_content"> </TableLayout> 

    The line layout file for the res / layout / table_row.xml table:

     <TableRow xmlns:android="http://schemas.android.com/apk/res/android"> <TextView android:text="" /> <TextView android:text="" /> </TableRow> 

    Activation file src / TableActivity.java:

     public void addRow(String cell0, String cell1) { TableLayout tableLayout = (TableLayout) findViewById(R.id.table); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); TableRow tr = (TableRow) inflater.inflate(R.layout.table_row, null); TextView tv = (TextView) tr.getChildAt(0); tv.setText(cell0); tv = (TextView) tr.getChildAt(1); tv.setText(cell1); tableLayout.addView(tr); } 

    It remains to call the method addRow in a loop and transfer the necessary data to it.

    Or replace the TableLayout with a GridView and use it and the adapter.