Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Android Studio Automatically Extract References From a Layout XML file into the Activity java file?

Back in the day MotoDev Studio (Eclipse based, put out by Motorolla) had a feature to extract references from your XML into your code. Standard Eclipse with the ADT didn't have this feature but was wondering if it's possible in Android Studio.

So for example given XML:

<Button
    android:id="@+id/my_button">

It would generate in your activity's class:

private Button mMyButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    mMyButton = (Button) findViewById(R.id.my_button);
}
like image 567
Geeks On Hugs Avatar asked Jun 05 '14 00:06

Geeks On Hugs


People also ask

Does Android Studio support XML?

Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. You can also use Android Studio's Layout Editor to build your XML layout using a drag-and-drop interface.

What is the use of an XML Activity file in an Android application?

xml file contains information of your package, including components of the application such as activities, services, broadcast receivers, content providers etc. It performs some other tasks also: It is responsible to protect the application to access any protected parts by providing the permissions.

What is the XML layout in Android Studio?

The XML layout file contains at least one root element in which additional layout elements or widgets can be added to build a View hierarchy.

How does XML work in Android Studio?

XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.


1 Answers

There is plugin to Android Studio called ButterKnifeZelezny, which provides feature you're requesting but only if you're using ButterKnife. You can select what you want to import and so on.

ButterKnifeZelezny

like image 63
skywall Avatar answered Oct 03 '22 03:10

skywall