Tôi có một ListView với một ArrayAdapter liên quan hiển thị nội dung của nó trong một số hoạt động. Thật không may nó đã cần thiết bây giờ, rằng ListView của tôi trong một trong các thiết lập không hiển thị tất cả các yếu tố của nó, nhưng chỉ là những nơi mà "tài sản" không được đặt thành true. Tôi muốn tránh sử dụng hai ArrayAdapters với nội dung khác nhau, kể từ đó tôi bằng cách nào đó cần phải giữ chúng trong đồng bộ. Tôi đã thử nó như thế này (phương pháp này bây giờ chỉ cần giả định rằng getView được gọi là trong bối cảnh mà chúng ta muốn ẩn một số yếu tố):Ẩn hàng khỏi ListView mà không chiếm không gian
public View getView(int position, View convertView, Context context) {
....
if(!arrayitems[position].isProperty()) { //arrayitems is the underlying array
convertView.setVisibility(View.VISIBLE);
}
else {
convertView.setVisibility(View.GONE);
}
return convertView;
}
này hoạt động, tuy nhiên tôi nhận được một hàng trắng nếu phần tử có isProperty == thật. Tôi muốn làm cho hàng vô hình theo nghĩa, rằng nó không chiếm bất kỳ không gian nữa. Điều đó có thể không?
Các tập tin XML được sử dụng cho convertView trông như thế này:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/text_item_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:maxLines="1"
android:ellipsize="none"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text_item_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<TextView android:id="@+id/text_item_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:maxLines="3"
android:ellipsize="none" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/text_item_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:textSize="10sp" />
<TextView
android:id="@+id/text_item_voted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
tôi đã cố gắng để phát lại tất cả android: layout_height = "wrap_content" với "fill_parent" nhưng nó không thay đổi bất cứ điều gì ...
Cảm ơn!
Tôi không nhận được nó, thuộc tính boolean giống nhau cho tất cả các phần tử vì nó là một thuộc tính cho bộ điều hợp. Làm thế nào nó có thể biết những gì hàng ẩn? –
xin lỗi, isProperty() tất nhiên là một phương pháp của các mục trong mảng – user1809923
nếu vẫn còn có vấn đề xin vui lòng kiểm tra câu trả lời của tôi nó sẽ làm việc cho chắc chắn. –