我的页面中有一个弹出窗口,其中包含一个列表视图。我已经在单独的XML文件中创建了弹出窗口的设计,并在主页面上某个按钮点击时加载它。该弹出窗口有一个列表视图,每一行都有一个图像和一个文本视图。但在Android 4.1中,我无法获得列表视图中的行选择,但在5.0中可以正常工作。请问有人可以建议我解决方案吗?
Listview:
<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>
列表视图项:
<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"/>
添加行点击监听器:
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) {
}
ListView
中删除此android:descendantFocusability="blocksDescendants"
。 - Piyush