0
我有一个问题,一些设备无法选择一个listview项目,我似乎无法弄清楚代码中出了什么问题 - 选择一个listview项目在我的设备和仿真器上正常工作。我已检查了重点,但这似乎不是问题。有人有主意吗?Android 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 22222222222222222222123456789"
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>
我们可以看到你的'OnItemClickListener'吗?另外,当你说它不起作用时,这是什么意思?只是'OnItemClickListener'不能触发?不应该发生什么? – Blumer 2013-03-05 19:50:52
我已更新主要评论。问题是当用户点击移动设备上的列表项时,它不会触发'onListItemClick'方法,并且不会加载详细信息活动。但是,我不确定为什么'onListItemClick'永远不会被调用。 – Abid 2013-03-05 23:28:16