Forum Archive

Need help populating a textView

npr3ha

Hello, I’m very new at this, but I’ve read the Ui docs provided with the app and done some googling, and I still can’t find a solution to a problem I’m having. I’m trying to populate a textView with the first element of a list, then change the contents of the textView after a button is pressed. However, I cannot get the textView to show the first element of the list. The error I’m getting points to the last line of my code (line 36), and says: ‘NoneType’ object has no attribute ‘text’. In my UI file, ‘examElement’ is the Name of the textView. I think I’ve followed the format of how I’ve seen others use textViews, but maybe not. Hopefully it’s an easy fix! Thanks

import ui

strokeExamElements = ["You can't teach an old dog new tricks","Age? Month?","Close eyes tightly, open eyes wide","Facial droop","Visual Fields (4 quadrants)","Horizontal gaze tracking","Arm Drift","Leg Drift","Sensory: Arm","Sensory: Leg","Coordination: Arm (finger-nose)","Coordination: Leg (heel-shin)"]

i = 0
listOfPositives = []

def nextExamElement():
    global i
    i += 1
    view['examElement'].text = strokeExamElements[i]

def animation():
    sender.alpha = 0.0 # fade out

# must define the button_tapped action prior to loading the view
def button_tapped(sender):

    buttonTitle = sender.title

    if buttonTitle == 'Negative':
        nextExamElement()

    elif buttonTitle == 'Positive':
        listOfPositives.append(strokeExamElements[i])
        print(listOfPositives)
        nextExamElement()

    elif buttonTitle == 'Show Results':
        # TODO: add new view to display the list of positive elements
        ui.animate(animation, duration=0.75)
        pass

view = ui.View()
ui.load_view('MendExam').present('sheet')
view['examElement'].text = strokeExamElements[i]
JonB

In your main bit, you want

view=ui.load_view(...)
view.present(...)

You were creating a view, but then loading and presenting a completely different view.

npr3ha

Ah. Everything works now. Thank you!