I need to load posts when I go to NewsScreen before it has loaded. When I put posts_show() method to init(), it says that "AttributeError: 'NoneType' object has no attribute 'text' cuz it hadn't created yet. What am I doing wrong? If you know please tell me, I'd really appreciate it
Here is my py file:
class NewsScreen(Screen):
SCREEN_NAME = meta.SCREENS.NEWS_SCREEN
dialog_post = None
dialog_plus = None
post = ObjectProperty()
md = ObjectProperty()
def __init__(self, **kw):
super().__init__(name=self.SCREEN_NAME, **kw)
self.response = news_request()
print(self.response.json())
#text=username.json()['username'], tertiary_text=content.json()
self.posts_show()
def post_change(self, post_text, post_content):
self.post.text = post_text
self.post.tertiary_text = post_content
def build(self):
return Builder.load_string(KV)
def posts_show(self):
for post in self.response.json().values():
post_text = post['username']
post_content = post['content']
self.post_change(post_text, post_content)
```
Here is kivy:
```py
ScrollView:
MDList:
id: md
ThreeLineAvatarIconListItem:
id: post
on_press: root.post_show()
text: "username"
secondary_text: "data"
tertiary_text: f"[color=#000000][font=Roboto]Post_text[/font] [/font][/color]"
IconLeftWidget:
icon: "language-python"