1

I'm writing custom view for charts. How does I can to pass fake data into view, when it is in edit mode? (I know about isInEditMode, but when I'm trying to pass data inside init block it crash preview)

That will be without any code in init (and you can look at setItems code)

And screenshot when i'm adding setItems inside init` enter image description here

But it still works when app running enter image description here

syncended
  • 81
  • 1
  • 7
  • Does this answer your question? [Android Studio layout editor cannot render custom views](https://stackoverflow.com/questions/16592965/android-studio-layout-editor-cannot-render-custom-views) – Uuu Uuu Jan 19 '21 at 01:33
  • 1
    The preview panel should also be showing you an error explaining why the rendering failed. It might be because of certain resources that are not supported in edit mode. – Subhrajyoti Sen Jan 19 '21 at 03:12

1 Answers1

0

I've found out the problem. (Thanks @Subhrajyoti Sen) I've looked at errors with render and that's shown me that method setItems is not found (quite strange). i've written next code

   init {
        if(isInEditMode) {
            valuesDiff = 12
            minValue = 3
            chartItems.addAll(listOf(10, 15, 3, 14, 12, 5))
        }
    }

And that solved the problem

syncended
  • 81
  • 1
  • 7