0
我想創建一個自定義佈局的列表視圖,將包含圖片和文字如何在不擴展列表活動的情況下創建自定義列表視圖?
但是我能找到的所有擴展列表活動的教程,但因爲我需要的按鈕和其他的東西添加到我不能擴展列表活動佈局。 我需要使用ListView使用自定義項目佈局
有關如何做到這一點的任何想法?
我想創建一個自定義佈局的列表視圖,將包含圖片和文字如何在不擴展列表活動的情況下創建自定義列表視圖?
但是我能找到的所有擴展列表活動的教程,但因爲我需要的按鈕和其他的東西添加到我不能擴展列表活動佈局。 我需要使用ListView使用自定義項目佈局
有關如何做到這一點的任何想法?
爲了在佈局中擁有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
是您實施的功能,它會將您的數據呈現在所需的圖像和文本佈局中。
有關ListView
和Adapter
的更多信息,請refer to the excellent documentation which Xamarin provides。
謝謝明白了吧 – 2015-03-26 04:29:18