Z
Z
Zaur Abdulgalimov2015-02-17 14:07:39
Android
Zaur Abdulgalimov, 2015-02-17 14:07:39

How to get root layout in android app?

Actually the question is in the title.
There is an activity: activity_main.xml . Tried to get like this:
findViewById(R.layout.activity_main);
I get null .
Who knows, tell me what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery, 2015-02-17
@abdulgalimov

The findViewById method looks for a View by its ID. You are trying to search by layout ID. It won't work.
You need to assign an ID to your root element in the template and search by that ID. Like this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/simple_id">
</LinearLayout>

findViewById(R.id.simple_id);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question