Skip to main content
The Choicely SDK allows you to create custom Fragment and embed Choicely content (articles, feeds, etc.) alongside your own UI logic.

Steps to Add a Custom Fragment

1. Create a Custom Fragment

Create a new fragment. This is where you’ll define your fragment’s layout and any custom logic.
public class YourCustomFragment extends Fragment {
    EditText editText;
    Button button;

    @Override
    protected int getLayout() {
        return R.layout.fragment_custom_fragment;
    }

    @Override
    protected void onLayoutCreated(@NonNull View layout, @Nullable Bundle savedInstanceState) {
        editText = layout.findViewById(R.id.edittext);
        button = layout.findViewById(R.id.toastButton);
    }
}

2. Create a Content Factory

Create a factory class that implements ChoicelyContentFragmentFactory. This factory is responsible for providing an instance of your custom content fragment.
public class YourContentFactory extends ChoicelyContentFragmentFactory {
    @Nullable
    @Override
    protected Fragment makeAppContentFragment(Context context, String type, @Nullable Uri internalUri, Bundle data) {
        Fragment fragment = null;
        switch (type) {
            case "special":
                final String internalUrl = data.getString(ChoicelyIntentKeys.INTERNAL_URL);
                if (!TextUtils.isEmpty(internalUrl)) {
                    final Uri uri = Uri.parse(internalUrl);
                    if (uri != null) {
                        final String key = uri.getLastPathSegment();
                        if (!CTextUtils.isEmpty(key)) {
                            switch (key) {
                                case "custom":
                                    fragment = YourCustomFragment();
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
            default:
                break;
        }
        return fragment;
    }
}

3. Register the Factory in Application Class

Finally, in your Application class (e.g., YourApplication.java or YourApplication.kt), add a call to ChoicelySDK.factory().setContentFactory() to use your custom Fragment.
import android.app.Application;
import com.choicely.sdk.ChoicelySDK;

public class YourApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        .....
        ChoicelySDK.factory().setContentFactory(new YourContentFactory());
    }
}

4. Set the Navigation Path

Define the navigation path in the builder for your custom Fragment.
How to use navigation
choicely://special/custom