Tôi có cửa sổ bật lên trong trang có chế độ xem danh sách. Tôi đã tạo ra thiết kế của popup trong một xml riêng biệt và tải nó trên một số nút bấm trong trang chính của tôi. Cửa sổ bật lên có một listview với mỗi hàng có một hình ảnh và một textview. Tôi không thể có được lựa chọn hàng trong listview trong Android 4.1 nhưng nó đang làm việc trong 5.0. Bất cứ ai có thể vui lòng đề nghị tôi giải pháp? listview:không thể chọn hàng trong chế độ xem danh sách trong cửa sổ bật lên trong 4.1 nhưng hoạt động trong android 5.0
<ListView android:id="@+id/lstSites"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fastScrollEnabled="true"
android:layout_margin="5dp"
android:descendantFocusability="blocksDescendants"></ListView>
</LinearLayout>
listview Item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false">
<ImageView
android:id="@+id/thumbImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:focusable="false"
android:focusableInTouchMode="false"/>
<TextView
android:id="@+id/tvSite"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Name"
android:focusable="false"
android:focusableInTouchMode="false"/>
thêm hàng nhấp chuột listner:
lstSiteMenu = (ListView) popupView.findViewById(R.id.lstSites);
adapter = new MenuItemsAdapter(SiteActivity.this, arrMenu);
// Attach the adapter to a ListView
lstSiteMenu.setAdapter(adapter);
lstSiteMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
final int position, long id) {
}
bất kỳ lỗi trong logcat?khi bạn nói hàng được chọn bạn có nghĩa là onItemClick không hoạt động hoặc bạn không nhận được vị trí? – virendrao
Xóa 'android: descendantFocusability = "blocksDescendants" 'khỏi' ListView'. – Piyush