我有一个带有复选框的列表视图。在一项新闻报道中,它会转到另一项活动。在长按下,将显示复选框并选择当前项。当OnItemClickListener实现时,它单独工作很好,但是当使用OnItemLOngClickListener时,正常的单击就没有注册
我的守则:
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 :",“未选中项”);};}}
编辑:删除android:clickable="true“和android:longClickable="true”这两个属性使其工作
发布于 2017-07-20 06:01:52
显然,删除android:clickable="true"和android:longClickable="true"使其工作。(为什么我不明白)
https://stackoverflow.com/questions/45206109
复制相似问题