无法在4.1中的弹出窗口中选择列表视图中的行但在android 5.0中工作

pan*_*kaj 11 android listview listviewitem android-4.1-jelly-bean

我的页面中有一个弹出窗口,其中包含listview.我已经在一个单独的xml中创建了弹出窗口的设计,并在我的主页面上点击了一些按钮.弹出窗口具有列表视图,每行包含图像和文本视图.我无法在android 4.1中的listview中获得行选择,但它在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>
Run Code Online (Sandbox Code Playgroud)

列表视图项目:

<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"/>
Run Code Online (Sandbox Code Playgroud)

添加行单击列表器:

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) {
            }
Run Code Online (Sandbox Code Playgroud)

Min*_*amy 0

您需要android:descendantFocusability="blocksDescendants"从您的ListView.

还要从和 中的行布局中删除android:focusable="false"和。android:focusableInTouchMode="false"ImageViewTextView

列表项应该是可点击的,但禁用它获取焦点