1

我的应用程序是一个简单的记事本类型的应用程序,在这个片段中,我想从数据库中检索笔记并将它们放入列表片段中。它工作得很好,直到我想选择一个列表项,我必须单击列表的文本,而不是像其他列表片段一样单击列表项。

这是代码

 public void fillData() {

        mDbHelper = new NotesDbAdapter(getActivity());
        mDbHelper.open();

        Cursor c = mDbHelper.fetchAllNotes();


        String[] from = new String[]{NotesDbAdapter.KEY_TITLE};

       int[] to = new int[] { R.id.text1};        

        // Now create an array adapter and set it to display using row
        @SuppressWarnings("deprecation")
        ListAdapter adapter = new  SimpleCursorAdapter(getActivity(),    R.layout.notes_row, c, from, to);
        this.setListAdapter(adapter);
    }

这是监听器方法

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    Intent N = new Intent(getActivity(), NoteEdit.class);
    N.putExtra(NotesDbAdapter.KEY_ROWID, id);
    startActivityForResult(N, ACTIVITY_EDIT);
}

notes_row.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/text1" xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="5dip"
    android:singleLine="true"/>
4

0 回答 0