Android ListFragment 适配器不允许用户点击

Android ListFragment Adapter not allowing user clicks

当我设置特定适配器时,我在尝试让我的 android 应用程序跟踪用户输入时遇到问题。

所以在我的片段 class 中我有这个函数,当片段被拾取到 activity.

时被拾取
@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
    System.out.println("clicked");
    // Indicates the selected item has been checked
    getListView().setItemChecked(pos, true);

    // Inform the QuoteViewerActivity that the item in position pos has been selected
    mListener.onListSelection(pos);
}


@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, getClass().getSimpleName() + ":entered onCreate()");
    super.onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    Log.i(TAG, getClass().getSimpleName() + ":entered onCreate()");
    return super.onCreateView(inflater, container, savedInstanceState);
}

public void onActivityCreated(Bundle savedState) {
    Log.i(TAG, getClass().getSimpleName() + ":entered onActivityCreated()");
    super.onActivityCreated(savedState);


    dbHelper= new dbHelper(getActivity());
    Cursor cursor = dbHelper.selectJoinDecksQuestions("jjj");
    cursor.moveToFirst();
    setListAdapter(new QuestionCursorAdapter(getActivity(), cursor));

}

调用适配器并使用光标返回的数据填充屏幕到文本视图列表中。问题是此数据的 none 是可选的。

如果我将 onActivityCreated 方法更改为显示此数据并且可以选择:

public void onActivityCreated(Bundle savedState) {
    Log.i(TAG, getClass().getSimpleName() + ":entered onActivityCreated()");
    super.onActivityCreated(savedState);

     Set the list adapter for the ListView
     Discussed in more detail in the user interface classes lesson
     setListAdapter(new ArrayAdapter<String>(getActivity(),
           R.layout.question_fragment, MainContentActivity.mTitleArray));
}

问题适配器看起来像这样

public QuestionCursorAdapter(Context context, Cursor c) {
    // that constructor should be used with loaders.
    super(context, c, 0);
    inflater = LayoutInflater.from(context);
    System.out.println("leaving constructor of the questioncursoradapter");
    System.out.println(getCount());
}


@Override
public void bindView(View view, Context context, Cursor cursor) {
    System.out.println("in bind view");
    TextView list_item = (TextView)view.findViewById(R.id.question_in_list);
    list_item.setText(cursor.getString(cursor.getColumnIndex(COLUMN_NAME_QUESTIONTEXT)));
    list_item.setMovementMethod(new ScrollingMovementMethod());
    int position = cursor.getPosition(); // that should be the same position

    System.out.println("leaving bind view");*/
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    System.out.println("newView in QuestionCursorAdapter entered");
    //question_fragment/cusoradaptertest
    View v = inflater.inflate(R.layout.question_fragment, null);
    System.out.println("leave newview");
    return v;

}

关于为什么 ArrayAdapter returns 数据在我的自定义 CursorAdapter 不可选的情况下是可选的,有什么想法吗?

所以我在适配器中设置了 clicklistener,一切正常!我唯一需要做的另一件事是允许片段将其 activity 传递给适配器,以便主 activity 可以从那里回调。我希望这不是性能低下的明智之举,但它似乎可以完成工作,所以我会在这里设置答案,以防其他人遇到这个问题。