Android ListView项目不可单击
我的ListView有一个问题:只能在分隔符上单击(自定义)项。我花了几个小时寻找解决办法,但没有任何办法 android:genderantfocusability=“blocksDescendants”无法正常工作。在每个子项上设置focusable=“false”也不起作用。有人知道这个问题的解决方案吗 ItemLayout.xml 麦克利克在我的房间里Android ListView项目不可单击,android,listview,cursor,customization,Android,Listview,Cursor,Customization,我的ListView有一个问题:只能在分隔符上单击(自定义)项。我花了几个小时寻找解决办法,但没有任何办法 android:genderantfocusability=“blocksDescendants”无法正常工作。在每个子项上设置focusable=“false”也不起作用。有人知道这个问题的解决方案吗 ItemLayout.xml 麦克利克在我的房间里 @Override public void onItemClick(AdapterView<?> adapter
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch(adapterView.getId()) {
case R.id.detailNoticeListView:
Cursor cursor = mNoticeAdapter.getCursor();
cursor.moveToPosition(i);
TextView textView = (TextView) view.findViewById(R.id.detailNoticeText);
Bundle bundle = new Bundle();
bundle.putString(NoticeDialog.EDIT_TEXT_ID, cursor.getString(cursor.getColumnIndex("_id")));
bundle.putString(NoticeDialog.EDIT_TEXT, textView.getText().toString());
NoticeDialog noticeDialog = new NoticeDialog();
noticeDialog.setTargetFragment(this, 0);
noticeDialog.setArguments(bundle);
noticeDialog.show(getFragmentManager(),"noticeDialog");
break;
}
}
@覆盖
公共无效onItemClick(AdapterView AdapterView、View视图、int i、long l){
开关(adapterView.getId()){
案例R.id.detailNoticeListView:
Cursor Cursor=mNoticeAdapter.getCursor();
光标移动位置(i);
TextView TextView=(TextView)view.findViewById(R.id.detailNoticeText);
Bundle=新Bundle();
bundle.putString(NoticeDialog.EDIT_TEXT_ID,cursor.getString(cursor.getColumnIndex(“\u ID”));
bundle.putString(NoticeDialog.EDIT_TEXT,textView.getText().toString());
NoticeDialog NoticeDialog=新NoticeDialog();
noticeDialog.setTargetFragment(这个,0);
noticeDialog.setArguments(bundle);
show(getFragmentManager(),“noticeDialog”);
打破
}
}
将android:clickable=“true”
添加到ItemLayout.xml
的线性布局中。另外,你的监听器在哪里?我已经解决了这个问题。
原因是我这样修改了TextView样式
<style name="elremFontMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">20dp</item>
<item name="android:textIsSelectable">true</item>
</style>
20dp
真的
问题是true
。
因此,我删除了这个属性,一切正常。从使用此列表视图的类中编写更多代码。您在哪里设置onItemClickListener?Add clickable=true的可能重复项也不起作用。侦听器位于我的片段中。我在问题中添加了。
public class NoticeAdapter extends CursorAdapter {
public NoticeAdapter(Context context, Cursor cursor) {
super(context, cursor, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.contact_detail_notice_item, parent, false);
return retView;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView textViewNotice = (TextView) view.findViewById(R.id.detailNoticeText);
textViewNotice.setText(cursor.getString(cursor.getColumnIndex(DatabaseHelper.NOTICE_TABLE_COLUMN_TEXT)));
}
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
switch(adapterView.getId()) {
case R.id.detailNoticeListView:
Cursor cursor = mNoticeAdapter.getCursor();
cursor.moveToPosition(i);
TextView textView = (TextView) view.findViewById(R.id.detailNoticeText);
Bundle bundle = new Bundle();
bundle.putString(NoticeDialog.EDIT_TEXT_ID, cursor.getString(cursor.getColumnIndex("_id")));
bundle.putString(NoticeDialog.EDIT_TEXT, textView.getText().toString());
NoticeDialog noticeDialog = new NoticeDialog();
noticeDialog.setTargetFragment(this, 0);
noticeDialog.setArguments(bundle);
noticeDialog.show(getFragmentManager(),"noticeDialog");
break;
}
}
<style name="elremFontMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textSize">20dp</item>
<item name="android:textIsSelectable">true</item>
</style>