i have overridden EditText as given in this link.
Now while declaring this field inside layout i am using
<com.and.ab1209.ClearableEditText
android:id=”@+id/edit_text_clearable”
android:layout_width=”fill_parent”
android:hint="My Hint Goes here"
android:layout_height=”wrap_content” />
How do i retrieve this hint value inside any of these constructor.
public ClearableEditText(Context context, AttributeSet attrs, int defStyle){...}
public ClearableEditText(Context context, AttributeSet attrs){...}
How do i do this?
You can access the standard xml attributes by doing the following inside your views constructor:
final String xmlns="http://schemas.android.com/apk/res/android";
//If you had a background attribute this is the resource id
int backgroundResource = attrs.getAttributeResourceValue(xmlns, "background", -1);
//This is your views hint
String hint = attrs.getAttributeValue(xmlns, "hint");
It does not matter if your view inherits from TextView, if you designate a hint using android:hint it will be accessible in your custom view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With