Reputation: 4220
I am trying to get a grasp on layouts, at the moment I'm trying to setup a layout that will contain multiple fields of data per line and display either a button on top or on the bottom at all times, like this:
Example, 5 rows:
Button
field A Field B Field C
field A Field B Field C
field A Field B Field C
field A Field B Field C
field A Field B Field C
This is what I have so far, I can display the button on the bottom but I'm unable to add multiple fields.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/ButtonCreate"
android:text="Create Game" android:layout_alignParentBottom="true" />
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/list"
android:layout_alignParentTop="true" android:layout_above="@id/ButtonCreate" />
<ProgressBar style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:id="@+id/progressBarBrowser" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></ProgressBar>
</RelativeLayout>
I've tried adding text fields as displayed below to the above code, but without success:
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
/>
</LinearLayout>
I am calling it in my Activity like this:
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));
Thanks for any ideas
Upvotes: 1
Views: 886
Reputation: 22371
From what I can tell, that second block of XML is supposed to represent an individual row in your listview. Is that correct? If so:
-First of all it needs to have 3 textviews: Field A, Field B, and Field C. Not "bottom and top".
-A simple ArrayAdapter isn't going to know which strings you want in which rows- It takes a list of strings, and displays one per row.
-You're not referencing the layout you defined (the one that currently has bottomtext and toptext) when you create the ArrayAdapter - You're telling it to use simple_list_item_1, a very basic "one textfield per row" layout used by the Android Framework.
To get this going, you're going to need to write your own adapter that knows how to place the incoming data in 3 different fields in a custom view. A good place to start would be Hello ListView on the Android Developer site. Good luck!
Upvotes: 1