Android ListView项目无法点击

时间:2014-11-02 14:00:14

标签: android listview cursor customization

我的ListView存在问题:(自定义的)项目只能在分隔符上单击。我已经花了几个小时寻找解决方案,但没有任何方法可以帮助我。

机器人:descendantFocusability =" blocksDescendants"选择正常工作。在每个子项上设置focusable =“false”也会起作用。有没有人知道这个问题的解决方案?

ItemLayout.xml     

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:paddingTop="@dimen/padding"
      android:paddingBottom="@dimen/padding"
      android:paddingLeft="@dimen/padding"
      android:paddingRight="@dimen/padding"
      android:layout_width="match_parent"
      android:descendantFocusability="blocksDescendants"
      android:layout_height="wrap_content" >

    <TextView
            android:layout_width="match_parent"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:layout_height="wrap_content"
            style="@style/elremFontMedium"
            android:id="@+id/detailNoticeText" />

</LinearLayout>

这是我的ListView

<ListView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/detailNoticeListView"/>

作为适配器,我使用了CursorAdapter

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)));
    }
}

onItemClick在我的Fragmant

 @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;
        }
    }

2 个答案:

答案 0 :(得分:1)

我已经解决了这个问题。 原因是我修改了TextView样式。

<style name="elremFontMedium" parent="@android:style/TextAppearance.Medium">
     <item name="android:textSize">20dp</item>
     <item name="android:textIsSelectable">true</item>
</style>

问题是<item name="android:textIsSelectable">true</item>。 所以我删除了这个属性,一切正常。

答案 1 :(得分:0)

android:clickable="true"添加到LinearLayout的{​​{1}}。您的ItemLayout.xml还在哪里?

相关问题