首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OnItemLongClickListener块OnItemClickListener

OnItemLongClickListener块OnItemClickListener
EN

Stack Overflow用户
提问于 2017-07-20 05:44:27
回答 1查看 102关注 0票数 0

我有一个带有复选框的列表视图。在一项新闻报道中,它会转到另一项活动。在长按下,将显示复选框并选择当前项。当OnItemClickListener实现时,它单独工作很好,但是当使用OnItemLOngClickListener时,正常的单击就没有注册

我的守则:

  1. 活动: myAdapter =新的myAdapter游标,0;bookList = (ListView) findViewById(R.id.android_list);bookList.setAdapter(myAdapter);bookList.setOnItemClickListener(新AdapterView.OnItemClickListener() {@覆盖公共空洞onItemClick(AdapterView adapterView,view,View,int i,long l) ){ inSelectMode=true;myAdapter.setCheckMode(真);CheckBox checkBox =checkBox(AdapterView);checkBox.setChecked(true);返回true;});
代码语言:javascript
复制
1. Adapter:

package com.example.blah.library1;import android.content.Context;import android.database.Cursor;import android.support.v4.widget.CursorAdapter;Importandroid.view.LayoutInflater;Importandroid.view.View;Importandroid.view.ViewGroup;Importandroid.widget.CheckBox;Importandroid.widget.TextView;/** **/公共类MyCursorCheckboxAdapter扩展了CursorAdapter {私有LayoutInflater cursorInflater;私有boolean[] checkedArray;检查器检查器;int checkCount;布尔isCheckMode;public boolean[] getSelection() {返回checkedArray;} public int getCheckCount() {返回checkCount;} public void setCheckMode{ this.isCheckMode = checkMode;notifyDataSetChanged();}公共布尔context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);getCheckMode() {返回isCheckMode;}公共接口检查器{ public isChecked(布尔isChecked);} public MyCursorCheckboxAdapter(上下文、游标c、int标志){Super(上下文、c、标志);cursorInflater = (LayoutInflater) cursorInflater=(LayoutInflater) checkedArray =新booleanc.getCount();checkCount = 0;isCheckMode = false;} catch ( cursorInflater.inflate(R.layout.row_layout_checkbox,e) {抛出新的ClassCastException(“活动必须实现检查器”);} checker.isAnyChecked(false);}@覆盖公共视图newView(上下文、游标、ViewGroup父程序){返回ClassCastException父程序,false);}@覆盖公共ClassCastException(视图v,上下文上下文,游标游标){ // Log.d(“游标:",cursor.getString(1));TextView title = ( TextView ) v.findViewById(R.id.listTitle);title.setText(cursor.getString(1));TextView author = (TextView) v.findViewById(R.id.listAuthor);author.setText(cursor.getString(2));TextView copies = (TextView) v.findViewById(R.id.listCopies);copies.setText(4);final copies.setText=()();(?)View.VISIBLE :View.GONE;最终int位置= cursor.getPosition();if (cursor.getInt(4) == 0) { // Log.d(“位置:",(整数)cursor.getPosition()).toString());checkBox.setEnabled(false);}checkBox.setOnClickListener(新的View.OnClickListener() {@覆盖公共view(视图)){布尔isChecked = ((CheckBox)视图).isChecked();if (isChecked) { // Log.d(“复选框:","isChecked”+Integer.toString(位置));checkCount++;if (checkCount == 1) checker.isAnyChecked(真);checkedArrayposition = true;}checkCount++{//Log.d(“复选框:","isNotChecked”+Integer.toString(位置));校验计数-;if (checkCount == 0) { checker.isAnyChecked(false);checkedArrayposition = false;// Log.d("Checker :",“未选中项”);};}}

  1. 我的列表项目布局:

编辑:删除android:clickable="true“和android:longClickable="true”这两个属性使其工作

EN

回答 1

Stack Overflow用户

发布于 2017-07-20 06:01:52

显然,删除android:clickable="true"android:longClickable="true"使其工作。(为什么我不明白)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45206109

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档