What is the Layout XML File Name?

Hello Kodular Community,

I am currently working on a Kodular extension and trying to access the layout XML files of different screens. Could anyone confirm what the exact layout file name for Screen is? Is it something like screen_layout.xml or activity_screen.xml, or does it have a different name?

Any insights would be greatly appreciated!

Thanks in advance. :blush:

If i am correct, If you are developing a extension using Niotron you won’t find standard XML layout files like activity_screen.xml. Kodular screens are dynamically created, so there’s no direct XML layout file associated with a screen.

However, if u r trying to programmatically add views inside an extension, you should use:

ComponentContainer to get the screen’s root layout.

Form class to access the current screen.

If you still wants to reference a layout file, u may need to create a custom XML layout inside the extension itself and inflate it manually using LayoutInflater.

2 Likes

I want to find a layout by using this command

context.getResources().getLayout(R.layout.layout_name);

but in fast extension build it shows error

R cannot be resolved to a variable

layout will be found after extension import in kodular before I need to build the extension. but it shows error. Is There any other way to connect layout with java code ?

I maybe wrong and strong with androud code but, Since you’re using Rush to build a Kodular extension, the issue arises because Rush does not support Android’s R resource system natively, May be.

Unlike Android Studio, where R.layout.layout_name is automatically generated, Rush compiles extensions without generating an R class for layouts, causing the R cannot be resolved error, in my view may be other extn devlopers may know mode deep and solution to your issue

May be this could help you,

  1. Use LayoutInflater with an External XML File

Since R.layout.layout_name does not work in Rush, you need to manually load the layout from an XML file stored in assets and inflate it programmatically.

Steps to Fix:

  1. Store your XML layout file in the assets folder inside your Rush project.

  2. Load it dynamically using LayoutInflater.

Code Example:

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;

public class MyExtension {
    private Context context;
    private ComponentContainer container;

    public MyExtension(ComponentContainer container) {
        this.container = container;
        this.context = container.$context();
    }

    public View getCustomLayout() {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View customView = inflater.inflate(context.getResources().getIdentifier("my_layout", "layout", context.getPackageName()), null);

        return customView;
    }
}

The getResources().getIdentifier() method dynamically fetches the layout without using R.layout.layout_name.

Ensure my_layout.xml is inside the assets/layout folder.

This method works in Rush and in all the Fast Extension Builder.

Dont mistake me if it not works for you

are u sure that it will work after app compiled?

Dynamically inflating an XML layout (getResources().getIdentifier())

:white_check_mark: Works only if the layout file is properly included in the final APK under res/layout.

If it throwaway an error just let me know

Also Storing an XML file in the assets folder and inflating it manually

:white_check_mark: Works after compiling if the layout is loaded using AssetManager.

And Instead, create layouts dynamically using Java (this will work 100% es expected after compilation).