Có cách nào để xóa mục đã chọn trong ListView không?Xóa danh sách lựa chọn đơn Chọn lựa
Các ListView được định nghĩa như thế này:
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="50dp"
android:id="@+id/example_list"
android:layout_weight="2"
android:choiceMode="singleChoice"/>
Và được làm đầy bằng một Adapter tùy chỉnh.
Các sản phẩm được chọn được đánh dấu bằng một Selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="#3E5260"
android:endColor="#3E5260"
android:angle="270" />
</shape>
</item>
<item android:state_activated="true">
<shape>
<gradient
android:startColor="#3E5260"
android:endColor="#3E5260"
android:angle="270" />
</shape>
</item>
</selector>
Bây giờ những gì tôi thực sự phải là 2 ListViews trong một hoạt động đơn lẻ và khi một mục là
chọn trong một ListView Tôi muốn bỏ chọn các mục trong ListView khác.
Cả ListViews nâng cao xử lý sau khi một mục được nhấp:
void DeviceList_Click(object sender, EventArgs e)
{
//easy enough to check which ListView raised the event
//but then I need to deselect the selected item in the other listview
}
Tôi đã thử những thứ như:
exampleList.SetItemChecked(exampleList.SelectedItemPosition, false);
và
exampleList.SetSelection(-1);
Nhưng điều đó dường như không làm việc.
Điều này dường như hoạt động, đã không cố gắng mà một, cảm ơn bạn – TimothyP
=> ký hiệu là gì? Tôi chưa bao giờ thấy được sử dụng trong mã Android. –
@IgorGanapolsky Đây là một biểu thức lambda, một phương thức ẩn danh. Đây là C#. Trong Java, bạn có triển khai 'IOnClickListener'. – Cheesebaron