ClickListener AND LongClickListener on ListFragment
<p>I have a ListFragment where I would like to add a normal click listener and a long one.</p>

<p>I override the onListItemClick() method on the ListFragment. Here, there is no problem it works.</p>

<p>Then I created an Adapter where I added an OnLongClickListener through setOnLongClickListener() in the getView() method:</p>

<pre><code>public class QuestionsAdapter extends BaseAdapter {

    private QuestionsBean questions = null;
    private LayoutInflater inflater = null;

    public QuestionsAdapter(LayoutInflater inflater) {
        this.inflater = inflater;
    }

    @Override
    public int getCount() {
        return (questions != null &amp;&amp; questions.getQuestionList() != null) ? questions.getQuestionList().size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return (questions != null &amp;&amp; questions.getQuestionList() != null) ? questions.getQuestionList().get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        QuestionBean question = ((QuestionsBean) questions).getQuestionList().get(position);
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_fragment_question, null);

            holder.questionItem = (TextView) convertView.findViewById(R.id.itemFragmentQuestions);
            holder.questionItem.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    System.out.println("test =&gt; it works");
                    ;
                    return false;
                }
            });

            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.questionItem.setText(question.getQuestion());

        return convertView;
    }

    private class ViewHolder {
        TextView questionItem;
    }

    public void setQuestions(QuestionsBean questions) {
        List&lt;QuestionBean&gt; temp = new ArrayList&lt;QuestionBean&gt;();
        if (questions != null &amp;&amp; questions.getQuestionList() != null) {
            for (QuestionBean question : questions.getQuestionList()) {
                if (question.isActivated()) {
                    temp.add(question);
                }
            }
            questions.setQuestionList(temp);
        }

        this.questions = questions;
        notifyDataSetChanged();
    }
}
</code></pre>

<p>Now, the longClickListener works but not the normal click anymore (actually it works like one time out of 10, or 15 or 20 (it depends...).</p>

<p>I have no idea why when I set both listener, the onListItemClick() doesn't work.</p>

<p>Any idea ?</p>

<p>Thanks for you help.</p>

<p>EDIT: My row xml
    
    </p>

<pre><code>    &lt;TextView
        android:id="@+id/itemFragmentQuestions"
        style="@style/ItemFragmentQuestion"
        android:layout_marginBottom="@dimen/itemFragmentQuestionsMarging"
        android:background="@drawable/background_validated" &gt;
    &lt;/TextView&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>EDIT:</p>

<p>My ListFragment class:</p>

<pre><code>public class QuestionsFragment extends ListFragment {

    public static final int VALIDATED = 1;
    public static final int IN_PROGRESS = 1;
    public static final int NON_OBSERVED = 1;

    private QuestionsAdapter adapter;
    private QuestionsBean questions;

    public QuestionsFragment() {

    }

    public QuestionsFragment(QuestionsBean questions) {
        this.questions = questions;
    }

    public int getShownIndex() {
        return getArguments() != null ? getArguments().getInt("index", 0) : 0;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        this.adapter = new QuestionsAdapter(inflater);
        registerForContextMenu(getListView());

        View questionsView = (LinearLayout) inflater.inflate(R.layout.fragment_questions, null);

        setListAdapter(adapter);

        return questionsView;
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        if (l == this.getListView()) {
            QuestionBean question = (QuestionBean) l.getItemAtPosition(position);
            TextView textView = (TextView) v.findViewById(R.id.itemFragmentQuestions);
            switch (question.getValue()) {
            case QuestionBean.OK:
                question.setValue(QuestionBean.NOK);
                textView.setBackgroundResource(R.drawable.background_in_progress);
                break;
            case QuestionBean.NOK:
                question.setValue(QuestionBean.NA);
                textView.setBackgroundResource(R.drawable.background_non_observed);
                break;
            case QuestionBean.NA:
                question.setValue(QuestionBean.OK);
                textView.setBackgroundResource(R.drawable.background_validated);
                break;
            }
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        refresh(this.questions);
    }

    public void refresh(QuestionsBean questions) {
        this.questions = questions;
        adapter.setQuestions(questions);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle("Menu Title");
        menu.add(0, v.getId(), 0, "Option 1");
        menu.add(0, v.getId(), 0, "Option 2");
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        if (item.getTitle() == "Option 1") {
            // Option 1 code here 
       } else if (item.getTitle() == "Option 2") {
            // Option 2 code here
       }
        return super.onContextItemSelected(item);
    }
}
</code></pre>

<p>@Barak As you can see, I set the Adapter in onCreateView() and when I put registerForContextMenu(getListView()) right after, I get an error. It seems that getListView() isn't set yet.</p>
