Reputation: 2669
I've got a page where I want to put a table in the middle and have buttons above and below. I've got the following XML for my layout. But even I can work out it won't work!
Edit: I've updated my XML to show what I want to achive. The tables inside, however it wont let me access by ListView listView = (ListView) findViewById(R.id.lvLocation);
<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" >
<Button
android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Add Item" />
<ListView
android:id="@+id/lvLocation"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/btnBack"
android:layout_alignParentLeft="true"
android:layout_below="@+id/btnAdd"
android:drawSelectorOnTop="false" >
</ListView>
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Back" />
</RelativeLayout>
My code: (with the Db call and array setup taken out)
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location_list_view);
ListView listView = (ListView) findViewById(R.id.lvLocation);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_2, android.R.id.text1, mArrayList);
int[] colors = {0, 0xFFFF0000, 0};
listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
listView.setDividerHeight(1);
listView.setAdapter(adapter);
}
}
Heres what i'm trying to achieve. Not the colours, just the concept:
Upvotes: 0
Views: 140
Reputation: 473
Instead of :
ListView listView = (ListView) findViewById (R.id.lvlocation);
Just use:
ListView listView = getListView();
Upvotes: 0
Reputation: 1363
I think this will help
<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" >
<Button
android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Add Item" />
<TableLayout
android:id="@+id/lvLocation"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/btnBack"
android:layout_alignParentLeft="true"
android:layout_below="@+id/btnAdd" >
</TableLayout>
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Back" />
</RelativeLayout>
Upvotes: 1