Từ :
“ListActivity có một cách bố trí mặc định mà bao gồm một đĩa đơn, toàn màn hình danh sách ở trung tâm của màn hình. Tuy nhiên, nếu bạn muốn, bạn có thể tùy chỉnh bố cục màn hình bằng cách đặt bố cục xem của riêng bạn với setContentView() trong onCreate(). Để làm điều này, quan điểm riêng của bạn phải có một đối tượng ListView với id "@android: id/danh sách"”
EDIT: đây là một ví dụ:
Các ListActivity có thể được tạo ra như thế này:
public class ListViewTest extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] values = {"One", "Two", "Three"};
setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, values));
setContentView(R.layout.main);
}
}
Cách bố trí main.xml
là như sau:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@android:id/list"></ListView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Test button"
android:id="@+id/TestButton"></Button>
</LinearLayout>
tôi có một bố trí tùy chỉnh, nhưng tôi không thể làm cho nó hiển thị bất cứ thứ gì nhưng bản thân listview, hoặc thành phần khác, nhưng không phải cả hai. Vì vậy, tôi muốn thấy một exampel mà thực sự hoạt động. – Roland
Tôi đã chỉnh sửa câu trả lời của tôi để nó bao gồm một ví dụ. Tôi vừa chạy ví dụ - làm việc như một sự quyến rũ. – ChrisJ
Cách tạo hoạt động danh sách bằng nút trong mỗi hàng bạn có thể xem từ http://stackoverflow.com/questions/3750380/android-listview-with-delete-button/3750594#3750594 – Zelimir