1

Estoy intentando agregar datos a una base de datos sqlite3 para luego poder leerlos, agregarlos a un RecycleView dinamicamente y luego borrarlos, pero directamente no estoy pudiendo hacer que luego de subir mis datos a la base se carguen automaticamente. Desde ya muchas gracias.

producto=[]

def cargarproductosbase():
    global producto
    con = sqlite3.connect("base.db")
    cur = con.cursor()
    cur.execute("select nombre from producto")
    print("se cargaron los productos")
    rows = cur.fetchall()
    for row in rows:
        for i in row:
            producto.append(i)
            print(producto)
    con.commit()
    con.close()
    print ("cargue estos datos")
    print (producto)

class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
                                 RecycleBoxLayout):
    ''' Adds selection and focus behaviour to the view. '''


class SelectableLabel(RecycleDataViewBehavior, Label):
    ''' Add selection support to the Label '''
    index = None
    selected = BooleanProperty(False)
    selectable = BooleanProperty(True)
    cols=2

    def refresh_view_attrs(self, rv, index, data):
        ''' Catch and handle the view changes '''
        self.index = index
        return super(SelectableLabel, self).refresh_view_attrs(
            rv, index, data)

    def on_touch_down(self, touch):
        ''' Add selection on touch down '''
        if super(SelectableLabel, self).on_touch_down(touch):
            return True
        if self.collide_point(*touch.pos) and self.selectable:
            return self.parent.select_with_touch(self.index, touch)

    def apply_selection(self, rv, index, is_selected):
        ''' Respond to the selection of items in the view. '''
        self.selected = is_selected
        if is_selected:
            aceptar=AceptarDonacion()
            aceptar.open()

            print("selection changed to {0}".format(rv.data[index]))
        else:
            print("selection removed for {0}".format(rv.data[index]))


class ExampleRV(RecycleView):
    global producto
    cargarproductosbase()
    def __init__(self, **kwargs):
        global producto

        super(ExampleRV, self).__init__(**kwargs)

        Clock.schedule_interval(self.reloading, 1)

    def reloading(self, nothing):
        global producto
        self.data = [{'text': str(x)} for x in producto]
        print (producto)

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.