Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: how to customize GridView layout dynamically?
    primarykey
    data
    text
    <p>i created an app which generates a GridView. each grid contains boxes. the number of boxes generated depends from the count of the names being retrieved from the database.</p> <p>Here's my code: main.xml</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;GridView android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numColumns="auto_fit" android:columnWidth="90dp" android:horizontalSpacing="10dp" android:verticalSpacing="10dp" android:gravity="center" android:stretchMode="columnWidth" android:orientation="horizontal" android:layout_marginTop="100dp" /&gt; </code></pre> <p></p> <p>layout1.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" android:layout_gravity="center" &gt; &lt;ImageView android:id="@+id/flag" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dp" android:src="@drawable/chair" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>a part of main.class</p> <pre><code>ArrayList&lt;HashMap&lt;String, String&gt;&gt; take = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); try { JSONObject jArray = new JSONObject(result); JSONArray stud_info = jArray.getJSONArray("info"); ca_list = new ArrayList&lt;ViewGridObject&gt;(); for (int i = 0; i &lt; info.length(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); JSONObject e = stud_info.getJSONObject(i); map.put("id", String.valueOf(i)); map.put("flag", Integer.toString(flags[0])); take.add(map); ca_list.add(new ViewGridObject(R.drawable.chair)); } myadapter = new AdapterViewGrid(main.this, list); gridView.setAdapter(myadapter); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } </code></pre> <p>currently, it displays a GridView like this.<img src="https://i.stack.imgur.com/EN1Ih.png" alt="Current GridView generated"></p> <p>but i want to customize the layout of the gridview dynamically. i want it to be like this..</p> <p><img src="https://i.stack.imgur.com/7Ki1o.png" alt="Desired GridView"></p> <p>pls. help..</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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