Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That depends. If you're sure that you'll have only a few rows then you can inflate add them in loop to the TableLayout. But note that you create view for every row.</p> <p>With lot of data create ListView and adapter for example based on CursorAdapter:</p> <pre><code>public class MyCursorAdapter extends CursorAdapter { private static final String TAG = "MyCursorAdapter"; private final int NAME_COLUMN; private final int ADDRESS_COLUMN; private final int STATE_COLUMN; public MyCursorAdapter(Context context, Cursor c) { super(context, c); NAME_COLUMN = c.getColumnIndexOrThrow("name"); ADDRESS_COLUMN = c.getColumnIndexOrThrow("address"); } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(context); View view = inflater.inflate(R.layout.custom_row, null); MyRowViewHolder rowData = new MyRowViewHolder(); rowData.name = (TextView) view.findViewById(R.id.name); rowData.address = (TextView) view.findViewById(R.id.address); rowData.name.setText(cursor.getString(NAME_COLUMN)); rowData.address.setText(cursor.getString(ADDRESS_COLUMN)); view.setTag(rowData); return view; } @Override public void bindView(View view, Context context, Cursor cursor) { MyRowViewHolder rowData = (MyRowViewHolder) view.getTag(); rowData.name.setText(cursor.getString(NAME_COLUMN)); rowData.address.setText(cursor.getString(ADDRESS_COLUMN)); } public static class MyRowViewHolder { TextView name; TextView address; } } </code></pre> <p>This approach doesn't create view for every row. I think that's better but needs more effort. To get table layout style use LinearLayout for rows with layout_weight for columns</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;TextView android:id="@+id/name" android:layout_weight="0.25" android:layout_width="0" android:layout_height="wrap_content"&gt; &lt;/TextView&gt; &lt;TextView android:id="@+id/address" android:layout_weight="0.75" android:layout_width="0" android:layout_height="wrap_content"&gt; &lt;/TextView&gt; &lt;/LinearLayout&gt; </code></pre> <p>To the ListView add header and footer if you want. </p>
 

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