Q:

Android button setOnClickListener error in a fragment

I am trying to handle a button click in fragment in android but I am having error at setOnClickListener. The button is not in the fragment but in a custom listview. Here is the code and xml that I am using.
programim_fragment_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"    
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

     <ListView
         android:id="@+id/listProgramim"
         android:layout_width="match_parent"
         android:layout_height="370dp"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true" 
         tools:listitem="@layout/list_programim">

listProgramim.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

 <Button
        android:id="@+id/btnRemove"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:src="@drawable/iconRemove" />

</RelativeLayout>

Fragment.java:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.programim_fragment_main, container, false);

         Button button = (Button) rootView.findViewById(R.id.btnRemove);
           button.setOnClickListener(new OnClickListener()
           {
                     @Override
                     public void onClick(View v)
                     {
                        // do something
                     } 
           });

    lstAdapter.insert(new ListClassProgramim("", 0), 0);

    return rootView;
}

what may cause this error?

A:

Your button is in the list item. You need to handle the setting of the clicklistener  in the lstAdapter when you inflate your list item layout.

