单击列表视图中的项目不起作用
Click item in listview does not work
当我点击任何列表项时没有任何反应,有人可以帮忙或告诉我问题出在哪里吗...?
这是我的列表视图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".defineBybeldbAlles">
<ListView
android:id="@+id/BybelHoofstukListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#ff303030"
android:dividerHeight="1dp"
android:layout_marginTop="5dp"
android:choiceMode="singleChoice" />
</RelativeLayout>
这是我的列表视图项:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/customButtonLayout"
android:layout_height="50dp"
style="@android:style/Widget.Button"
android:focusable="false"
android:layout_width="200dp">
<! hoofstuk_id is hidden and is only for reference >
<TextView
android:text="id"
android:id="@+id/hoofstuk_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
</TextView>
<TextView
android:textColor="#000"
android:text="nommer"
android:layout_height="wrap_content"
android:id="@+id/custom_row_hoofstuktext"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp">
</TextView>
</LinearLayout>
</LinearLayout>
这是我在 activity:
中的 OnItemclicklistener
listviewHoofstuk.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick (AdapterView<?> arg0, View view, int arg2, long arg3){
//on selecting a hoofstk
//BybelActivityVers will be launched to show verse inside
Intent hoofstukIntent = new Intent(BybelActivityHoofstuk.this,BybelActivityVers.class);
//send hoofstuk_id to VersActivity to get verse under that book
String hoofstuk_id_na_vers =((TextView)view.findViewById(R.id.hoofstuk_id)).getText().toString();
hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers);
startActivity(hoofstukIntent);
}
});
我查看了其他一些解决方案,但对我的情况没有任何效果,我添加了这段代码,但使用与否都没有区别:
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
在此处使用 AdapterView 获取 adpater 项目视图你应该使用 parent 来查找 TextView
listviewHoofstuk.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//on selecting a hoofstk
//BybelActivityVers will be launched to show verse inside
Intent hoofstukIntent = new Intent(BybelActivityHoofstuk.this,BybelActivityVers.class);
//send hoofstuk_id to VersActivity to get verse under that book
String hoofstuk_id_na_vers =((TextView)parent.findViewById(R.id.hoofstuk_id)).getText().toString();
hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers);
startActivity(hoofstukIntent);
}
});
您的列表项正在获得焦点。在 LinearLayout 标签中设置下面的行 my Listview Item xml
文件
android:clickable="false"
你的 intent 会在没有集中注意力的情况下触发并正常工作我已经检查过了...一旦它对你有用请告诉我...
这是您的解决方案:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".defineBybeldbAlles">
<ListView
android:id="@+id/BybelHoofstukListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#ff303030"
android:dividerHeight="1dp"
android:layout_marginTop="5dp"/>
</RelativeLayout>
在您的列表视图项目中,您必须进行以下更改:
<LinearLayout
android:id="@+id/customButtonLayout"
android:layout_height="50dp"
style="@android:style/Widget.Button"
android:layout_width="200dp">
<! hoofstuk_id is hidden and is only for reference >
<TextView
android:text="id"
android:id="@+id/hoofstuk_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
</TextView>
<TextView
android:textColor="#000"
android:text="nommer"
android:layout_height="wrap_content"
android:id="@+id/custom_row_hoofstuktext"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp">
</TextView>
</LinearLayout>
</LinearLayout>
如果不只是点击对此答案的评论,这应该可以解决您的问题。之后您将开始获取列表视图的 OnItemClick() 事件。
我删除了
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
然后应用
android:clickable="false"
它没有用,但在摆弄之后我发现
android:clickable="false"
android:focusable="false"
组合成功了!
这在 listview 项 中应用,就在 LinearLayout 之后。
我测试过并且可以确认它也适用于 Gridview。
当我点击任何列表项时没有任何反应,有人可以帮忙或告诉我问题出在哪里吗...?
这是我的列表视图:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".defineBybeldbAlles">
<ListView
android:id="@+id/BybelHoofstukListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#ff303030"
android:dividerHeight="1dp"
android:layout_marginTop="5dp"
android:choiceMode="singleChoice" />
</RelativeLayout>
这是我的列表视图项:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/customButtonLayout"
android:layout_height="50dp"
style="@android:style/Widget.Button"
android:focusable="false"
android:layout_width="200dp">
<! hoofstuk_id is hidden and is only for reference >
<TextView
android:text="id"
android:id="@+id/hoofstuk_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
</TextView>
<TextView
android:textColor="#000"
android:text="nommer"
android:layout_height="wrap_content"
android:id="@+id/custom_row_hoofstuktext"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp">
</TextView>
</LinearLayout>
</LinearLayout>
这是我在 activity:
中的 OnItemclicklistener listviewHoofstuk.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick (AdapterView<?> arg0, View view, int arg2, long arg3){
//on selecting a hoofstk
//BybelActivityVers will be launched to show verse inside
Intent hoofstukIntent = new Intent(BybelActivityHoofstuk.this,BybelActivityVers.class);
//send hoofstuk_id to VersActivity to get verse under that book
String hoofstuk_id_na_vers =((TextView)view.findViewById(R.id.hoofstuk_id)).getText().toString();
hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers);
startActivity(hoofstukIntent);
}
});
我查看了其他一些解决方案,但对我的情况没有任何效果,我添加了这段代码,但使用与否都没有区别:
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
在此处使用 AdapterView 获取 adpater 项目视图你应该使用 parent 来查找 TextView
listviewHoofstuk.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//on selecting a hoofstk
//BybelActivityVers will be launched to show verse inside
Intent hoofstukIntent = new Intent(BybelActivityHoofstuk.this,BybelActivityVers.class);
//send hoofstuk_id to VersActivity to get verse under that book
String hoofstuk_id_na_vers =((TextView)parent.findViewById(R.id.hoofstuk_id)).getText().toString();
hoofstukIntent.putExtra("hoofstuk_id", hoofstuk_id_na_vers);
startActivity(hoofstukIntent);
}
});
您的列表项正在获得焦点。在 LinearLayout 标签中设置下面的行 my Listview Item xml
文件
android:clickable="false"
你的 intent 会在没有集中注意力的情况下触发并正常工作我已经检查过了...一旦它对你有用请告诉我...
这是您的解决方案:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".defineBybeldbAlles">
<ListView
android:id="@+id/BybelHoofstukListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#ff303030"
android:dividerHeight="1dp"
android:layout_marginTop="5dp"/>
</RelativeLayout>
在您的列表视图项目中,您必须进行以下更改:
<LinearLayout
android:id="@+id/customButtonLayout"
android:layout_height="50dp"
style="@android:style/Widget.Button"
android:layout_width="200dp">
<! hoofstuk_id is hidden and is only for reference >
<TextView
android:text="id"
android:id="@+id/hoofstuk_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
>
</TextView>
<TextView
android:textColor="#000"
android:text="nommer"
android:layout_height="wrap_content"
android:id="@+id/custom_row_hoofstuktext"
android:layout_width="wrap_content"
android:layout_marginLeft="10dp">
</TextView>
</LinearLayout>
</LinearLayout>
如果不只是点击对此答案的评论,这应该可以解决您的问题。之后您将开始获取列表视图的 OnItemClick() 事件。
我删除了
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
然后应用
android:clickable="false"
它没有用,但在摆弄之后我发现
android:clickable="false"
android:focusable="false"
组合成功了!
这在 listview 项 中应用,就在 LinearLayout 之后。
我测试过并且可以确认它也适用于 Gridview。