So here it is. Everything except one line per grid entry requires something special. This is not perfect code in any way, but it will help.
Start with your base layout.
Let's just say this is called mainlist.xml
<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" > <ListView android:id="@+id/itemList" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </RelativeLayout>
So you have Relative with ListView. Pretty basic right?
In your activity you will need such a code.
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mainlist); GetAndAssociateData(); } public void GetAndAssociateData() { ListView list = (ListView)findViewById(R.id.itemList); final ArrayList<CountedItem> items; list.setAdapter(new CountedItemAdapter(getApplicationContext(), R.id.countedItemRow, items, this)); }
Everything that is outside this line requires not only an adapter, but also a layout for each element.
The CountedItemAdapter is the adapter in this case (it tells how to populate the view).
countedItemRow is the layout for each item.
/src/CountedItemAdapter.java
public CountedItemAdapter(Context context,int textViewResourceId, ArrayList<CountedItem> objects,CountedItemActivity parentActivity) { super(context, textViewResourceId, objects); this.context = context; this.items = objects; this.parentActivity = parentActivity; // TODO Auto-generated constructor stub } public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (view == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.countedItemRow, null); } if (items != null){ CountedItem item = items.get(position); if (item != null) { TextView thing= (TextView) view.findViewById(R.id.thing); if (thing!= null) { thing.setText(item.GetThingText()); } TextView thingCount = (TextView) view.findViewById(R.id.thingCount); if (thingCount != null) { thingCount .setText(item.GetThingCount()); } } } return view; }
/res/layout/countedItemRow.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/countedItemRow" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/thing" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="0dp" android:layout_y="0dp" /> <TextView android:id="@+id/thingCount" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="0dp" android:layout_y="150dp" /> </RelativeLayout>