我有一个问题,即某些设备无法选择 listview 项目,而且我似乎无法找出代码中的问题 - 选择 listview 项目在我的设备和模拟器上都可以正常工作。我已经检查了焦点,但这似乎不是问题。有人有想法么?
公共类 GroupListFragment 扩展 ListFragment
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
Group group = (Group) listView.getItemAtPosition(position);
mCallbacks.onItemSelected(group);
}
公共类 GroupListActivity 扩展 FragmentActivity 实现 GroupListFragment.Callbacks
@Override
public void onItemSelected(Group group) {
if (twoPaneLayout) {
// seems to work fine
Bundle arguments = new Bundle();
arguments.putLong(GroupDetailFragment.GROUP_ITEM_ID, group.getId());
GroupDetailFragment fragment = new GroupDetailFragment();
fragment.setArguments(arguments);
replaceDetailPane(fragment);
} else {
// does not work on some mobile devices
Intent detailIntent = new Intent(this, GroupDetailActivity.class);
detailIntent.putExtra(GroupDetailFragment.GROUP_ITEM_ID, group.getId());
startActivity(detailIntent);
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left);
}
}
列表显示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@drawable/list_item_group_background" >
<ListView
android:id="@id/android:list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:divider="@null"
android:dividerHeight="0dp"
android:verticalScrollbarPosition="left" />
<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textIsSelectable="false" />
</LinearLayout>
定制项目:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_group_item_background"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp"
tools:ignore="HardcodedText" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/list_item_group_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:singleLine="true"
android:text="User 22222222222222222222123456789012345"
android:textColor="@drawable/list_item_group_item_header_text"
android:textSize="16sp"
android:textStyle="bold"
android:typeface="sans" />
<TextView
android:id="@+id/list_item_group_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:singleLine="true"
android:text="Group status..."
android:textColor="@drawable/list_item_group_item_status_text"
android:textSize="12sp"
android:typeface="sans" />
</LinearLayout>
<TextView
android:id="@+id/list_item_group_callout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:background="@drawable/callout_background"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:singleLine="true"
android:text="new"
android:textColor="@drawable/callout_text"
android:textSize="10sp"
android:textStyle="bold"
android:typeface="sans" />
</LinearLayout>
<LinearLayout
android:id="@+id/list_item_group_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_item_group_toolbar_background"
android:baselineAligned="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:orientation="horizontal"
android:padding="5dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center" >
<Button
android:id="@+id/list_item_group_edit"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@drawable/list_item_group_edit_background"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center" >
<Button
android:id="@+id/list_item_group_delete"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@drawable/list_item_group_delete_background"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
</LinearLayout>