Image Button not removing selected item from listview
<p>I created a calorie app for my class project. I'm trying to remove an item from a listview. The way I have it setup is I created an imagebutton in the listivew .xml. For some reason when the user clicks on the imagebutton "fooddelete" it doesnt do anything.</p>

<p>Thank you so much, I'm new to android studio this my first app and working with fragments.</p>

<pre><code>public class FragmentHome extends   Fragment  implements 

View.OnClickListener {


public TextView caloriesTotal
private TextView caloriesRemain;

private ListView listView;
private LinearLayout mLayout;

private Animation anim;
ImageButton AddEntrybtn;
ImageButton ResetEntry;
ImageButton FoodDelete;
Context context;

int goalCalories;
int totalCalorie;
int tdee;
Button mButton;
String formattedCalories ;
String formattedRemain ;
//Database
private DatabaseHandler dba;
private ArrayList&lt;Food&gt; dbFoods = new ArrayList&lt;&gt;();
private CustomListViewAdapter foodAdapter;
private Food myFood ;
//fragment
private android.support.v4.app.FragmentManager fragmentManager;
private FragmentTransaction fragmentTransaction;
public FragmentHome() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myView = inflater.inflate(R.layout.fragment_home, container, 
    false);
caloriesTotal = (TextView) myView.findViewById(R.id.tv_calorie_amount);

caloriesRemain = (TextView) myView.findViewById(R.id.calorieRemain);

listView = (ListView) myView.findViewById(R.id.ListId);



SharedPreferences prefs = 
PreferenceManager.getDefaultSharedPreferences(getActivity());

SharedPreferences userInfo =getContext().getSharedPreferences("userInfo",0);
tdee= userInfo.getInt("tdee",0);
caloriesRemain.setText(formattedRemain);
AddEntrybtn = (ImageButton) myView.findViewById(R.id.AddItems);

AddEntrybtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            ((appMain) getActivity()).loadSelection(4);
        }
    });




  ResetEntry = (ImageButton) myView.findViewById(R.id.ResetEntry);
 ResetEntry.setOnClickListener(this);


  ** Get Error Here  **
     //  void   
    // android.widget.ImageButton.setOnClickListener
   // (android.view.View$OnClickListener)' on a null object reference
   **   **

   FoodDelete = (ImageButton) rootView.findViewById(R.id.fooddelete);

    FoodDelete.setOnClickListener(this);

refreshData();

anim= AnimationUtils.loadAnimation(getActivity(), R.anim.fading);
listView.startAnimation(anim);

return myView;
}


public void reset ()  {

dbFoods.clear();

dba = new DatabaseHandler(getActivity());

ArrayList&lt;Food&gt; foodsFromDB = dba.getFoods();
//Loop
for (int i = 0; i &lt; foodsFromDB.size(); i ++){

String name = foodsFromDB.get(i).getFoodName();
String date = foodsFromDB.get(i).getRecordDate();
int cal = foodsFromDB.get(i).getCalories();
int foodId = foodsFromDB.get(i).getFoodId();

Log.v("Food Id", String.valueOf(foodId));

myFood= new Food();
myFood.setFoodId(foodId);
myFood.setFoodName(name);
myFood.setCalories(cal);
myFood.setRecordDate(date);

dbFoods.clear();

dbFoods.remove(myFood);
foodsFromDB.remove(myFood);
dba.deleteFood(foodId);
 }
dba.close();
//setting food Adapter:
foodAdapter = new CustomListViewAdapter(getActivity(), 
R.layout.row_item,dbFoods);
listView.setAdapter(foodAdapter);
foodAdapter.notifyDataSetChanged();

anim= AnimationUtils.loadAnimation(getActivity(), R.anim.fading);
listView.startAnimation(anim);
}

public void refreshData (){

dbFoods.clear();
dba = new DatabaseHandler(getActivity());

ArrayList&lt;Food&gt; foodsFromDB = dba.getFoods();

totalCalorie = dba.totalCalories();

formattedCalories = Utils.formatNumber(totalCalorie);
formattedRemain = Utils.formatNumber(  tdee-totalCalorie);

 //setting the editTexts:
 caloriesTotal.setText("Total Calories: " + formattedCalories);

 caloriesRemain.setText(formattedRemain);

 SharedPreferences prefs = 
 PreferenceManager.getDefaultSharedPreferences(getContext());

 SharedPreferences userInfo = 
 getContext().getSharedPreferences("userInfo",0);
int tdee= userInfo.getInt("tdee",0);
caloriesRemain.setText(" "+tdee);

    //Loop
for (int i = 0; i &lt; foodsFromDB.size(); i ++){

String name = foodsFromDB.get(i).getFoodName();
String date = foodsFromDB.get(i).getRecordDate();
int cal = foodsFromDB.get(i).getCalories();
int foodId = foodsFromDB.get(i).getFoodId();

Log.v("Food Id", String.valueOf(foodId));

myFood= new Food();
myFood.setFoodId(foodId);
myFood.setFoodName(name);
myFood.setCalories(cal);
myFood.setRecordDate(date);
dbFoods.add(myFood);
}
dba.close();
//setting food Adapter:
foodAdapter = new CustomListViewAdapter(getActivity(), 
R.layout.row_item,dbFoods);
listView.setAdapter(foodAdapter);
foodAdapter.notifyDataSetChanged();

anim= AnimationUtils.loadAnimation(getActivity(), R.anim.fading);
listView.startAnimation(anim);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

Bundle username = getActivity().getIntent().getExtras();

String username1 = username.getString("Username");

TextView userMain= (TextView) getView().findViewById(R.id.User);

userMain.setText(username1);

SharedPreferences userInfo = 
getContext().getSharedPreferences("userInfo", 0);
int tdee= userInfo.getInt("tdee",0);
caloriesRemain.setText(formattedRemain);

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

 @Override
 public void onDetach() {
 super.onDetach();

 startActivity( new Intent(getContext(),MainActivity.class));
  }


  @Override
  public void onClick(View v) {
  switch (v.getId()) {
  case R.id.AddItems:

            AddEntry addEntry = new AddEntry();

            fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.replace(R.id.FragmentHolder, addEntry)

                    .commit();
                     break;

    case R.id.ResetEntry:


            reset();
            anim = AnimationUtils.loadAnimation(getActivity(), 
            R.anim.fading);
            listView.startAnimation(anim);
            break;



    case  R.id.fooddelete:

            AlertDialog.Builder adb=new AlertDialog.Builder(getContext());
            adb.setTitle("Delete?");
            adb.setMessage("Are you sure you want to delete " + dbFoods);

            adb.setNegativeButton("Cancel", null);
            adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

             foodAdapter.remove(dbFoods.get(dbFoods.indexOf(myFood)));
                    foodAdapter.notifyDataSetChanged();
                }
            });

            break;
          }


       }
      }
</code></pre>