Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

How to access a properties a tableView if that table is in a scrollableView and update that table?

$
0
0

Hi, I'm doing a app where at scrollableView I add tableViews, but after I want change the order the rows the tables with 2 buttons that are within the table.

This code I already did but with a only tableView and I add direct to window

this is the code:

App.js

var random=require('random');
var winExOne = Ti.UI.createWindow({
exitOnClose:true,
width:'100%',height:'100%',
backgroundImage:'/image/e1-1200x1000.png'   
});
var btnRevisar=Ti.UI.createButton({
    title:'Enviar',
    borderRadius:80,borderWidth:3,
    backgroundColor:'blue',borderColor:'purple',
    font:{fontSize:10, fontFamily:'sans-serif'},
    animatedCenter:{x:30,y:40},
    width:'10%',height:'15%',
    top:'75%',right:'10%',
    color:'#fff'
});
 
 
var algoritmo=['ESCRIBIR "Introduce un numero0"','LEER res1','SI num >= 0 ENTONCES2','ESCRIBIR "es positivo"3','SINO4','Escribir "es negativo5"','FINSI6'];
var arregloRandom=[];
var dataRow=[];
arregloRandom=random.getRandom(algoritmo.length);
for(var i = 0; i < algoritmo.length; i++) {
       var ran=arregloRandom[i]-1;
        var row = Ti.UI.createTableViewRow({
        title:ran
        });
        row.add(Ti.UI.createLabel({
            title:'orden'+ran,
            text: algoritmo[ran], textAlign: 'left',
            width: Ti.UI.FILL, color: '#fff'
        }));
        row.add(Ti.UI.createButton({
            action: 'moveUp',
            width: '15%', 
            right: '1%',bottom:4,top:4,
            backgroundImage:'/image/up.png',color:'#fff'
        }));
        row.add(Ti.UI.createButton({
            action: 'moveDown',
            width: '15%',
            right: '20%',bottom:4,top:4,
            backgroundImage:'/image/down.png',color:'#fff'
        }));
        dataRow.push(row);
    }
 
    var tabla = Ti.UI.createTableView({
        width:'80%',
        top:'10%',left:'3%',
        separatorColor:'#fff',separatorStyle:2,
        data: dataRow
    });
 
    tabla.addEventListener('click', function(evt) {
        ud.play();
        var action = evt.source.action,
            index = evt.index,
            isFirstRow = index === 0,
            isLastRow = index + 1 === dataRow.length;
 
        if(action === 'moveUp' && !isFirstRow) {
            tabla.data=random.reacomodo(index,index-1,dataRow);
        }
        else if(action === 'moveDown' && !isLastRow) {
           tabla.data=random.reacomodo(index,index+1,dataRow);
        }
 
    });
 
btnRevisar.addEventListener('click',function(){ 
    var validar;
    var arregloPosiciones=[];
      for(i=0;i<algoritmo.length;i++)
      {arregloPosiciones.push(JSON.stringify(tabla.data[0].rows[i].title));}
 
      validar=random.validarEjercicio(arregloPosiciones);
      if(validar)
      {
        corre.play();
        alert("Es correcto puedes avanzar");
      }
      else
      {
        fallo.play();
        alert("Es incorrecto el acomodo");
      }
    });
winExOne.add(tabla);
winExOne.open():
Ramdom.js
function random()
{
}
 
random.getRandom = function (aleatorio)
{
var arreglo=[];
var num;
var repe;   
for(var i=0; i<aleatorio; i++)
{
    do{
        num=(Math.floor(Math.random()*aleatorio)+1);
        repe=repetido(num,aleatorio,arreglo);
    }while(repe!=false);
    arreglo.push(num);
}
return arreglo;
}
 
function repetido(num,con,arreglo)
{
var repe=false;
for(var i=0; i<con; i++)
{
if(num==arreglo[i])
repe=true;
}   
return repe;
}
 
random.validarEjercicio=function(arreglo)
{
    //var corre=true;
    var arregloValidar=[];
    for(var i=0; i<arreglo.length; i++)
    {arregloValidar[i]=i}
    for(var i=0; i<arreglo.length; i++)
    {   
    if(arreglo[i]!=arregloValidar[i])
    return false;   
    }
    return true;
}
 
random.reacomodo=function(index1,index2,arreglo)
{
 
     var dataRow=arreglo;
     var temp = dataRow[index1];
         dataRow[index1] = dataRow[index2];
        dataRow[index2] = temp;
        return  dataRow;
 
}
 
module.exports=random;
But now the tableViewRow is in a scrollableView and I dont know how I can access and change the orden.

this is my new code:

var winExOne = Ti.UI.createWindow({
exitOnClose:true,
width:'100%',height:'100%'  
});
 
Titanium.Database.install('pruebas.sqlite', 'db');
 
var scrollView=Ti.UI.createScrollableView({
    showPagingControl:true
});
 
 
 
var dbAlgoritmo=Titanium.Database.open('db');
var rows = dbAlgoritmo.execute('select * from exe');
var algoritmo=[];
var algo=[];
var views=[];
var c=0;
while(rows.isValidRow())
{
    algo[c]=rows.fieldByName('algoritmo');
    c++;
    rows.next();
}
for(var i=0; i < algo.length; i++)
{
    algoritmo[i]=algo[i].split(",");
}
 
 
 
for(var i=0; i<algoritmo.length; i++)
{
    var dataRow=[];
for(var j=0; j<algoritmo[i].length; j++)
{
        var row = Ti.UI.createTableViewRow({
        title:algoritmo[i][j]
        });
        row.add(Ti.UI.createLabel({
            title:'orden'+algoritmo[i],
            text: algoritmo[i][j], textAlign: 'left',
            width: Ti.UI.FILL, color: '#fff'
        }));
        row.add(Ti.UI.createButton({
            action: 'moveUp',
            title:'?',
            width: '15%', 
            right: '1%',bottom:4,top:4,
            backgroundColor:'red',color:'#fff'
        }));
        row.add(Ti.UI.createButton({
            action: 'moveDown',
            title:'?',
            width: '15%',
            right: '20%',bottom:4,top:4,
            backgroundColor:'orange',color:'#fff'
        }));
        dataRow.push(row);
 
}   
 
    var tabla = Ti.UI.createTableView({
        width:'80%',
        top:'10%',left:'3%',
        separatorColor:'#fff',separatorStyle:2,
        data: dataRow
    });
 
scrollView.addView(tabla);
}
 
var views=scrollView.getViews();
scrollView.addEventListener('scrollend',function(e){
 
    alert(scrollView.currentPage);
 
}) ;  
 
 
dbAlgoritmo.close();
winExOne.add(scrollView);
winExOne.open();
Any idea of how do ?

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>