Skip to content

Simple library to automatically set up reference to widget declared in Android XML Layout file into your Java code.

License

Notifications You must be signed in to change notification settings

gilanghamidy/heliosky-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

heliosky-toolkit.ui

What's this?

Tired of writing and seeing findByViewId every single time you want to retrieve reference to your widget from Android layout file? This is a simple library to help you set up widget reference for your Activity, Fragment, or any View.

The Old Way

public class MyActivity extends Activity {
  TextView mTextViewName;
  EditText mEditTextYourMomma;
  
  protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// Get root view
		View root = activity.findViewById(android.R.id.content);
		
		this.mTextViewName = root.findViewById(R.id.MyActivity_TextView_Name);
		this.mEditExtYourMomma = root.findViewById(R.id.MyActivity_TextView_YourMomma);
		
		this.mTextViewName.setText("Your momma is so big!");
  }
}

The Helios Way

import com.heliosky.toolkit.ui.WidgetReferenceFunctions;

public class MyActivity extends Activity {
  @WidgetReference(R.id.MyActivity_TextView_Name)
  TextView mTextViewName;
  
  @WidgetReference(R.id.MyActivity_EditText_YourMomma)
  EditText mEditTextYourMomma;
  
  protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		WidgetReferenceFunctions.prepareWidgetReference(this);
		
		this.mTextViewName.setText("Your momma is so big!");
	}
}

How The Magic Works?

Reflection.

License

The library is Copyright (c) 2014 Gilang Mentari Hamidy @ Heliosky.com, and distributed under the MIT License.

About

Simple library to automatically set up reference to widget declared in Android XML Layout file into your Java code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages