Is it possible to initialize all UI elements of certain type (like all TextViews or all LineraLayouts or …) in a some kind of loop?
I have many layouts with a lot of the elements of the same type and it’s really painful to do it all just by typing.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use RoboGuice .It doesn’t use loops, but helps you to Inject your View, Resource, System Service, or any other object in to your code.
RoboGuiceis a framework that brings the simplicity and ease of Dependency Injection to Android, using Google’s own Guice library.To give you an idea, take a look at this simple example of a typical Android activity:
This example is 19 lines of code. If you’re trying to read through onCreate(), you have to skip over 5 lines of boilerplate initialization to find the only one that really matters: name.setText(). And complex activities can end up with a lot more of this sort of initialization code.
Compare this to the same app, written using RoboGuice:
In this example, onCreate() is much easier to take in at a glance. All the platform boilerplate is stripped away and you’re left with just your own app’s business logic. Do you need a SystemService? Inject one. Do you need a View or Resource? Inject those, too, and RoboGuice will take care of the details.
RoboGuice’s goal is to make your code be about your app, rather than be about all the initialization and lifecycle code you typically have to maintain in Android.
This text is from here