2015-03-25 22 views

回答

1

爲了在佈局中擁有ListView,您不一定使用ListActivity。使用ListActivity的所有樣品都存在,因爲人是懶惰;)

所以只需使用一個普通Activity,然後你只需要在ListView添加到您正在設置爲內容視圖的佈局。這可能是這個樣子:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="0" 
     android:layout_weight="1" /> 
    <Button 
     android:id="@+id/somethingButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Do something" /> 
    <Button 
     android:id="@+id/elseButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Do something else" /> 
</LinearLayout> 

然後像你OnCreate方法的任何其他Activity你這樣做:

SetContentView(Resource.Layout.myLayout); // myLayout.axml 

var listView = FindViewById<ListView>(Resource.Id.listView); 
listView.Adapter = new MyAdapter(context, itemsSource); 

var somethingButton = FindViewById<Button>(Resource.Id.somethingButton); 
var elseButton = FindViewById<Button>(Resource.Id.elseButton); 

... more code ... 

ListView只是一個佈局,就像任何其他的,所以沒有什麼神奇的約它。本示例中的MyAdapter是您實施的功能,它會將您的數據呈現在所需的圖像和文本佈局中。

有關ListViewAdapter的更多信息,請refer to the excellent documentation which Xamarin provides

+0

謝謝明白了吧 – 2015-03-26 04:29:18

相關問題