Android Custom View Constructor

You don’t need the first one, as that just won’t work. The third one will mean your custom View will be usable from XML layout files. If you don’t care about that, you don’t need it. The fourth one is just wrong, AFAIK. There is no View constructor that take a Map as the third … Read more

How can I get the canvas size of a custom view outside of the onDraw method?

For drawing purposes, you should not really use the dimensions of the Canvas object. Just use the dimensions provided to you in the onSizeChanged method. You can either store the dimensions for use in the onDraw method or resize/draw to a backing bitmap that you can draw with later. Update: Quickly whipped up some code, … Read more

How to get an enum which is created in attrs.xml in code

There does not seem to be an automated way to get a Java enum from an attribute enum – in Java you can get the numeric value you specified – the string is for use in XML files (as you show). You could do this in your view constructor: TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.IconView, … Read more

Can a custom View know that onPause has been called?

Yes you can using below code, @Override protected void onVisibilityChanged(@NonNull View changedView, int visibility) { super.onVisibilityChanged(changedView, visibility); if (visibility == View.VISIBLE) //onResume called else // onPause() called } @Override public void onWindowFocusChanged(boolean hasWindowFocus) { super.onWindowFocusChanged(hasWindowFocus); if (hasWindowFocus) //onresume() called else // onPause() called } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); // onDestroy() called } @Override … Read more

How to create custom view programmatically in swift having controls text field, button etc

The CGRectZero constant is equal to a rectangle at position (0,0) with zero width and height. This is fine to use, and actually preferred, if you use AutoLayout, since AutoLayout will then properly place the view. But, I expect you do not use AutoLayout. So the most simple solution is to specify the size of … Read more

android data binding with a custom view

In your Custom View, inflate layout however you normally would and provide a setter for the attribute you want to set: private MyCustomViewBinding mBinding; public MyCustomView(…) { … LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mBinding = MyCustomViewBinding.inflate(inflater); } public void setMyViewModel(MyViewModelObject obj) { mBinding.setMyViewModel(obj); } Then in the layout you use it in: <layout xmlns…> <data> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)