2011-06-27 25 views
10

Tôi đang cố gắng lấy các mục danh sách của mình trong một ListView có thể nhấp. Hiện tại, chúng có thể nhấp (xem ảnh chụp màn hình của tôi) nhưng chúng chỉ có thể nhấp trong hình chữ nhật mà văn bản chiếm.Chiều rộng của khu vực có thể nhấp trong ListView w/onListItemNhấp vào

Tôi đang sử dụng protected void onListItemClick(ListView l, View v, int position, long id) { cho các mục danh sách có thể nhấp.

Đây là list.xml tôi:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
<ListView android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
<TextView android:id="@+id/android:empty" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/no_favorites"/> 

và row.xml tôi:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 
    <TextView android:id="@+id/artist" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"/> 
    <TextView android:id="@+id/songtitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_alignParentRight="true"/> 
    <TextView android:id="@+id/album" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_alignParentRight="true"/> 
    <TextView android:id="@+id/playtime" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:layout_alignParentRight="true"/> 
    <TextView android:id="@+id/playlistnum" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:layout_alignParentRight="true" 
     android:visibility="gone" /> 
</LinearLayout> 

here's the screenshot example: (người dùng mới không được phép đăng hình ảnh. .. càu nhàu ... có siêu liên kết!)

Trong list.xml, Listview có và roid: layout_width = "fill_parent" vì vậy nó phải là toàn bộ chiều rộng của màn hình. (Tất cả các mục trong row.xml cũng là width = "fill_parent".) Tôi đang thiếu gì?

Trả lời

11

TextView trong list.xml của bạn cần được đặt thành fill_parent. Việc lựa chọn sau đó sẽ phù hợp với chiều rộng của ListView cha.

 android:layout_width="wrap_content" 
+0

Đã thử, không hoạt động. TextView đó chỉ được sử dụng khi danh sách trống. :/ – Civilian

+3

hmmm .... Ah, chỉ khác biệt khác trong mã của tôi và của bạn sẽ là LinearLayout cũng được đặt thành fill_parent trên layout_width. Hãy thử một lần. Nếu điều đó không hiệu quả, tôi sẽ mở mã của tôi và đăng nó ở đây. – JLB

+3

Để rõ ràng tôi đã đề cập đến LinearLayout trong list.xml của bạn trong bình luận cuối cùng của tôi. Nó được đặt thành wrap_content. Làm việc cho tôi thay đổi điều đó thành fill_parent. – JLB

Các vấn đề liên quan