I'm trying to display an Image when listView is empty but unfortunately, it is not showing that image when list view is empty whenever the list is empty.

I have tried to move setEmptyView to move into oncreate, before that I tried to check whether cursor is empty or not if empty then call setemptyview method

*Fence Activity*
In this activity, I'm trying to use setEmptyView method.

```
public class FenceActivity extends AppCompatActivity {
    List<Fence> fenceList;
    SQLiteDatabase sqLiteDatabase;
    ListView listViewFences;
    FenceAdapter fenceAdapter;
    DataBaseHelper dataBaseHelper;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.savedfences);

        listViewFences = findViewById(R.id.fencesListView);
        fenceList = new ArrayList<>();

        showFencesFromDatabase();
    }

    public void showFencesFromDatabase() {

        dataBaseHelper = new DataBaseHelper(this);
        Cursor cursor = dataBaseHelper.getAllData();
        if (cursor.moveToFirst()) {
            do {
                fenceList.add(new Fence(cursor.getInt(0), cursor.getDouble(1), cursor.getDouble(2), cursor.getInt(3)));
            } while (cursor.moveToNext());
        }
        cursor.close();
        fenceAdapter = new FenceAdapter(FenceActivity.this, R.layout.list_layout_fences, fenceList);
        listViewFences.setAdapter(fenceAdapter);

        listViewFences.setEmptyView(findViewById(R.id.emptyElement));
    }

    public void reloadFencesFromDatabase() {
        dataBaseHelper = new DataBaseHelper(this);
        Cursor cursor = dataBaseHelper.getAllData();
        fenceList.clear();
        if (cursor.moveToFirst()) {
            do {
                fenceList.add(new Fence(cursor.getInt(0), cursor.getDouble(1), cursor.getDouble(2), cursor.getInt(3)));
            } while (cursor.moveToNext());
        }
        cursor.close();
        fenceAdapter = new FenceAdapter(FenceActivity.this, R.layout.list_layout_fences, fenceList);
        listViewFences.setAdapter(fenceAdapter);
        listViewFences.setEmptyView(findViewById(R.id.emptyElement));
    }
}

```

*Savedfences.xml*

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

    <ListView
        android:id="@+id/fencesListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ImageView
        android:id="@+id/emptyElement"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:dividerHeight="1dp"
        android:visibility="gone"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"/>
</RelativeLayout>

```

*Adapter Class*

```
public class FenceAdapter extends ArrayAdapter<Fence> {

    Context context;
    int listLayoutRes;
    List<Fence> fenceList;
    DataBaseHelper dataBaseHelper;
    FenceActivity fenceActivity;

    public FenceAdapter(Context context, int listLayoutRes, List<Fence> fenceList) {
        super(context, listLayoutRes, fenceList);
        this.context = context;
        this.listLayoutRes = listLayoutRes;
        this.fenceList = fenceList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.list_layout_fences, null);
        }

         final Fence fence = fenceList.get(position);

        TextView textViewSno = convertView.findViewById(R.id.textViewSnoLabel);
        TextView textViewLat = convertView.findViewById(R.id.textViewLatitudeValue);
        TextView textViewLon = convertView.findViewById(R.id.textViewLongitudeValue);
        TextView textViewRadi = convertView.findViewById(R.id.textViewRadiusValue);

        textViewSno.setText(Integer.toString(fence.getSno()));
        textViewLat.setText(String.valueOf(fence.getLat()));
        textViewLon.setText(String.valueOf(fence.getLon()));
        textViewRadi.setText(Integer.toString(fence.getRadius()));

        Button buttonDel = convertView.findViewById(R.id.buttonDeleteFence);

        buttonDel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle("Are you sure");
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dataBaseHelper = new DataBaseHelper(context);
                        fenceActivity = (FenceActivity)context;
                        dataBaseHelper.deleteDataById(fence);
                        fenceActivity.reloadFencesFromDatabase();
                 }
                });
                builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
            }
        });
        return convertView;
    }
}

```

What changes can I make to display that image when the list is empty.