How to use a base layout and custom it in android

fandro

I'am trying to create a Linear Layout and an editText base on a layout.xml file here is the java code :

private EditText editText(int _intID) {
        EditText editText = (EditText)findViewById(R.id.player_name);
        editText.setId(_intID);
        editText.setHint("Element "+_intID);
        editTextList.add(editText);

        return editText;
    }

    private LinearLayout linearlayout(int _intID)
    {

        LinearLayout LLMain= (LinearLayout)findViewById(R.id.linear_player_base);

        LLMain.setId(_intID);
        LLMain.addView(editText(_intID));

        LLMain.setOrientation(LinearLayout.VERTICAL);
        linearlayoutList.add(LLMain);
        return LLMain;

    }

Here is the xml layout I want to use as a base :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginBottom="5dp"
    android:layout_weight="1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingLeft="40dp"
    android:paddingRight="40dp"
    android:id="@+id/linear_player_base">
<EditText
    android:id="@+id/player_name"
    android:background="@drawable/input"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:imeOptions="actionSend"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center_horizontal"
    />
</LinearLayout>

I don't understand why when I do :

LinearLayout LLMain= (LinearLayout)findViewById(R.id.linear_player_base);
and then :

LLMain.setId(_intID);

I have this error : Attempt to invoke virtual method 'void android.widget.LinearLayout.setId(int)' on a null object reference

why LLMain is null ?

jonhid

You must inflate a custom view with you layout and the find the linear layout in this view... Do it like this:

LayoutInflater inflater = getLayoutInflater();
View v = inflater.inflate(R.layout.playerLayout, null);

LinearLayout LLMain= (LinearLayout) v.findViewById(R.id.linear_player_base);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use a base layout and custom it in android

From Dev

How to use Android Layout and custom GUI design in this

From Dev

How to use Android Layout and custom GUI design in this

From Dev

Android - How to layout and use a custom View?

From Dev

How to adjust custom Layout in base Adapter

From Dev

Android base layout with buttons to use in multiple activities

From Dev

How to use Percentage for android layout?

From Dev

How to select custom layout to use in Apache POI

From Dev

Symfony EntityType - How to use custom layout?

From Dev

How to use android.support.design.widget.TabLayout to create custom layout of tab?

From Dev

How to refresh the view of a custom layout in Android?

From Dev

How to put a custom .psd button in android layout?

From Dev

Android: how to configure sizing of a custom layout

From Dev

Android: How to use tools with include layout

From Dev

How do I use view in android layout?

From Dev

How to get rid of relative layout or use a free layout. (Android)

From Dev

Android Custom Layout for listview

From Dev

Android MenuItem Custom Layout

From Dev

Android Custom Layout for listview

From Dev

Custom layout of button in android

From Dev

How to use a custom class (which extends View class) in activity class to draw path without changing the other parts of the main layout in android

From Dev

How to use custom css file for layout of a module in Yii2

From Dev

Use view/layout of the base Fragment

From Dev

Use view/layout of the base Fragment

From Dev

How to create custom bent layout with imageview and text android?

From Dev

Android: How to dynamically add a "Custom View" into a linear layout

From Dev

How to preview Android ListView with custom row and header layout

From Dev

How to handle event of item and tab in action bar with custom layout in android?

From Dev

How to define a custom Application theme to specify a default background for a layout in Android?

Related Related

  1. 1

    How to use a base layout and custom it in android

  2. 2

    How to use Android Layout and custom GUI design in this

  3. 3

    How to use Android Layout and custom GUI design in this

  4. 4

    Android - How to layout and use a custom View?

  5. 5

    How to adjust custom Layout in base Adapter

  6. 6

    Android base layout with buttons to use in multiple activities

  7. 7

    How to use Percentage for android layout?

  8. 8

    How to select custom layout to use in Apache POI

  9. 9

    Symfony EntityType - How to use custom layout?

  10. 10

    How to use android.support.design.widget.TabLayout to create custom layout of tab?

  11. 11

    How to refresh the view of a custom layout in Android?

  12. 12

    How to put a custom .psd button in android layout?

  13. 13

    Android: how to configure sizing of a custom layout

  14. 14

    Android: How to use tools with include layout

  15. 15

    How do I use view in android layout?

  16. 16

    How to get rid of relative layout or use a free layout. (Android)

  17. 17

    Android Custom Layout for listview

  18. 18

    Android MenuItem Custom Layout

  19. 19

    Android Custom Layout for listview

  20. 20

    Custom layout of button in android

  21. 21

    How to use a custom class (which extends View class) in activity class to draw path without changing the other parts of the main layout in android

  22. 22

    How to use custom css file for layout of a module in Yii2

  23. 23

    Use view/layout of the base Fragment

  24. 24

    Use view/layout of the base Fragment

  25. 25

    How to create custom bent layout with imageview and text android?

  26. 26

    Android: How to dynamically add a "Custom View" into a linear layout

  27. 27

    How to preview Android ListView with custom row and header layout

  28. 28

    How to handle event of item and tab in action bar with custom layout in android?

  29. 29

    How to define a custom Application theme to specify a default background for a layout in Android?

HotTag

Archive