Android:how to instantiate my custom view with attributeset constructor?

Maybe I don't get what you are doing or why you're doing it, but I find your attempt with the AttributeSet quite complicated I'd suggest you create another constructor like this public CalendarView(Context context, int backgroundRessourceID) { super(context); setBackgroundResource(backgroundRessourceID); } And then instantiate your CalendarView like this CalendarView cv = new CalendarView(this, R.drawable.0_bg); cv. SetLayoutParams(new LayoutParams(LayoutParams. MATCH_PARENT, 30)) Hopefully this solved your issue.

Maybe I don't get what you are doing or why you're doing it, but I find your attempt with the AttributeSet quite complicated. I'd suggest you create another constructor like this public CalendarView(Context context, int backgroundRessourceID) { super(context); setBackgroundResource(backgroundRessourceID); } And then instantiate your CalendarView like this CalendarView cv = new CalendarView(this, R.drawable.0_bg); cv. SetLayoutParams(new LayoutParams(LayoutParams.

MATCH_PARENT, 30)); Hopefully this solved your issue ...

Thanks,I'm using like this now,but there are a lot of attribute to use ,include custom and system provide,i'm curious how to use attributeset. – gaconel Apr 28 at 10:31.

My custom view has dynamic custom attribute,e.g. The backgroundimage attribute,assign via current week. I wan't to use construtor CalendarView(Context context, AttributeSet attrs) to pass several attribute,and I try to instantiate the attributeset with Xml. AsAttributeSet,but it can't work.

Can anyone tell me how to do. Note:my custom view has dynamic attribute ,so I don't wan't to instantiate the custom view via xml layout. My solution is incorrect?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions