Android-setOnItemClickListener()不';listview中的t
我无法解决不使用setOnItemClickListener()的问题。 (API minSdkVersion 19,targetSdkVersion 21,编译'com.android.support:appcompat-v7:21.0.3') 我试着在不同的地方放:Android-setOnItemClickListener()不';listview中的t,android,listview,listener,Android,Listview,Listener,我无法解决不使用setOnItemClickListener()的问题。 (API minSdkVersion 19,targetSdkVersion 21,编译'com.android.support:appcompat-v7:21.0.3') 我试着在不同的地方放: android:genderantfocusability=“blocksDescendants” android:clickable=“false” android:focusable=“false” android:foc
- android:genderantfocusability=“blocksDescendants”
- android:clickable=“false”
- android:focusable=“false”
- android:focusableInTouchMode=“false”
- android:textIsSelectable=“false”
- categoriesListView.SetDegenantFocusability(ViewGroup.FOCUS\u BLOCK\u子体)李>
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u ADJUST\u PAN)李>
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.gallery_tab_categories, container, false);
super.onCreate(savedInstanceState);
categoriesListView = (ListView) view.findViewById(R.id.listViewCategories);
categoriesListView.setAdapter( new GalleryCategoriesListAdapter( getActivity(), CATEGORIES_DATA ) );
//dbHandler = new ShoppingListDatabaseHandler(getActivity());
categoriesListView.setLongClickable(true);
final GalleryCategoriesListAdapter itemAdapter = new GalleryCategoriesListAdapter(getActivity(), CATEGORIES_DATA);
registerForContextMenu(categoriesListView);
categoriesListView.setAdapter(itemAdapter);
//categoriesListView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); //getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
categoriesListView.setOnItemClickListener(new AdapterView.setOnItemClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
clickedItemIndex = position;
return false;
}
});
//if (dbHandler.getItemsCount() != 0){CATEGORIES_DATA.addAll(dbHandler.getAllItems());
return view;
}
public View onCreateView(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图=充气机。充气(R.layout.gallery\u选项卡\u类别,容器,错误);
super.onCreate(savedInstanceState);
categoriesListView=(ListView)view.findViewById(R.id.listViewCategories);
setAdapter(新的GalleryCategoriesListAdapter(getActivity(),CATEGORIES_数据));
//dbHandler=新ShoppingListDatabaseHandler(getActivity());
categoriesListView.setLongClickable(true);
final GalleryCategoriesListAdapter itemAdapter=新GalleryCategoriesListAdapter(getActivity(),CATEGORIES_数据);
registerForContextMenu(分类列表视图);
categoriesListView.setAdapter(itemAdapter);
//categoriesListView.SetDegenantFocusability(ViewGroup.FOCUS\u BLOCK\u Substands);//getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT\u INPUT\u ADJUST\u PAN);
categoriesListView.setOnItemClickListener(新的AdapterView.setOnItemClickListener(){
@凌驾
公共布尔值长单击(AdapterView父项、视图、整型位置、长id){
单击编辑索引=位置;
返回false;
}
});
//如果(dbHandler.getItemScont()!=0){CATEGORIES_DATA.addAll(dbHandler.getAllItems());
返回视图;
}
我的xml与listview
<?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="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
<ListView
android:id="@+id/listViewCategories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:focusable="false"
android:focusableInTouchMode="false" />
<!--android:focusable="false"-->
<!--android:clickable="false"-->
带有单个项目的xml
<?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="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
<!--android:autoLink="all"-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/itemCategoryName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
<!--android:descendantFocusability="blocksDescendants"-->
<!--android:clickable="false"-->
<!--android:focusable="false"-->
<!--android:focusableInTouchMode="false"-->
<!--android:textIsSelectable="false"-->
可能我尝试了太多的东西,使我的代码不清晰您必须删除此内容
android: enfocable = "false"
android: focusableInTouchMode = "false"
//试试这个
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:gravity="center_vertical" >
<ListView
android:id="@+id/listViewCategories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout/>
如果您将指定事件发生在子项上的列表视图,则不会单击该项
我改变了这个片段:
categoriesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
categoriesListView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
}
});
谢谢您的回答。我尝试了您所说的,但仍然没有改变。