Im trying to add a list view to my activity. Here is what is suppose to happen: The user clicks on a button and that uses an asyncTask to get data from the internet. That data should then be added to the list view. The data comes from a table online therefore it there are 10 rows in the table then there should be 10 values in the Listview.
But I'm having some problems. First of all can a listview be added to a pre-existing layout and be updated on the fly?
Does a list view mean you cannot use the setContentView() method and have to use setListAdapter?
- If you have a layout that already has two buttons arranged on it can the list view be added in below them and still be implemented using the setContentView() method?
Thanks
Edit
Updated Code - Which works:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView( R.layout.new_sightings );
ListView list = getListView();
list.setAdapter( new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, values ) );
list.setTextFilterEnabled( true );
}
XML Layout
?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation = "vertical">
<TableLayout
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
>
<TableRow
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1"
>
<TextView
android:id = "@+id/txtTitle"
android:layout_width = "wrap_content"
android:layout_height = "fill_parent"
android:layout_weight = "1"
android:gravity = "center"
android:text = "ISS Predictions"
android:textStyle="bold"
android:textColor = "#FFFFFF"
/>
<Button
android:id="@+id/reloadTen"
android:layout_height="wrap_content"
android:layout_width ="fill_parent"
android:layout_gravity = "right"
android:layout_weight = "1"
android:text = "Reload"
android:textColor = "#FFFFFF"
android:textStyle = "bold"
android:background = "#000000"
/>
</TableRow>
</TableLayout>
<ListView
android:id = "@+id/android:list"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:textSize = "15dp"
android:textStyle = "bold"
/>
</LinearLayout>