AviranAbady / CookieBar2

Android library for displaying text messages, notifications and alerts at the top or bottom of the screen. A great alternative for toast and snackbar alerts.
Apache License 2.0
667 stars 74 forks source link

Your custom cookie view is missing one of the default required views #8

Closed Suvam-Dawn closed 5 years ago

Suvam-Dawn commented 5 years ago

Your custom cookie view is missing one of the default required views. When i add custom layout, i got this error.

CookieBar.build(DancingFrameActivity.this)
                .setCustomView(R.layout.devices_list)
                .setCustomViewInitializer(new CookieBar.CustomViewInitializer() {
                    @Override
                    public void initView(View v) {
                        devicelist = v.findViewById(R.id.listView);
                        pairedDevices = myBluetooth.getBondedDevices();
                        ArrayList list = new ArrayList();
                        if (pairedDevices.size() > 0) {
                            for (BluetoothDevice bt : pairedDevices) {
                                list.add(bt.getName() + "\n" + bt.getAddress()); //Get the device's name and the address
                            }
                        } else {
                            Toast.makeText(getApplicationContext(), "No Paired Bluetooth Devices Found.", Toast.LENGTH_LONG).show();
                        }

                        final ArrayAdapter adapter = new ArrayAdapter(DancingFrameActivity.this, android.R.layout.simple_list_item_1, list);
                        devicelist.setAdapter(adapter);
                    }
                })
                .setAction("Close", new OnActionClickListener() {
                    @Override
                    public void onClick() {
                        CookieBar.dismiss(DancingFrameActivity.this);
                    }
                })
                .setEnableAutoDismiss(false)
                .setSwipeToDismiss(false)
                .setCookiePosition(CookieBar.BOTTOM)
                .show();

Layout:

<?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"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="10dp"
    android:paddingBottom="10dp">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Paired Devices"
        android:id="@+id/textView"
        android:drawableLeft="@drawable/ic_bluetooth"
        android:drawablePadding="10dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/textView" />
</RelativeLayout>
AviranAbady commented 5 years ago

Hello @Suvam-Dawn, The current version of CookieBar2, assumes you will create a custom view while keeping all the required original views with the correct IDs.

In future versions I will remove that requirement but for now, your custom layout must contain a

All the uncessery views can set visibility to View.GONE if you don't need them in your custom cookie.