0
votes

I am new to titanium. I am creating a custom table view with row. I have added 4 views in a row. Each corresponding view has label --->> Check In time, Check out time,Note and Time. Check In and Check Out gives time for the task. Note is to add note and Time to display difference in Check In and Check Out Time. I want to update Note for particular task in database accoding to current Check In time. I am not getting the way to capture the text on current Check In Time Label when that particular click of row. If i get the check in time then i will update the corresponding row in database according to current check in time.

Here is my code.

function set(date,intime,outtime) { var date1=date;

        var section = Ti.UI.createTableViewSection();
         row1 = Ti.UI.createTableViewRow({layout:"horizontal"});


        inview=Ti.UI.createView({
               width:"25%",
        });

        inlabel=Ti.UI.createLabel({
             text:intime,
            font:{fontSize:13}

        });
        inview.add(inlabel);



        outview=Ti.UI.createView({
             width:"25%",

        });

        outlabel=Ti.UI.createLabel({
            text:outtime,
            font:{fontSize:13}
        });

        outview.add(outlabel);

        inview.addEventListener('click',function(e){


               // Ti.API.info(';',e.row1.rowID);                

                var picker=Ti.UI.createPicker();
                picker.showTimePickerDialog({

                    callback: function(e){

                          if(e.cancel)
                          {
                             Ti.API.info('user canceled dialog');
                          }
                          else{

                                Ti.API.info('user selected date'+e.value);

                               var d=new Date(e.value);                                     
                               var time=String.formatTime(d);                                            

                               var newintime=d.getTime();

                                Ti.API.info(':'+time);                

                             //   var total=calculatetime(newintime,currouttime);

                             //   timelabel.text=total;

                                inlabel.text=time;                                                                        
                               //updateintime(date1,inlabel.text);



                          }
                    }

                });

        });


        outview.addEventListener('click',function(e){

                var picker=Ti.UI.createPicker();
                picker.showTimePickerDialog({

                    callback: function(e){

                          if(e.cancel)
                          {
                             Ti.API.info('user canceled dialog');
                          }
                          else{

                                Ti.API.info('user selected date'+e.value);

                                 var d=new Date(e.value);
                                 var time=String.formatTime(d);

                                 var newoutime=d.getTime();

                                 Ti.API.info(''+newoutime);      

                              //     var total=calculatetime(currintime,newoutime);

                                // timelabel.text=total;                                

                                 outlabel.text=time;
                             //   updateoutime(date1,outlabel.text);

                          }
                    }

                });

        });



        var timeview=Ti.UI.createView({
              width:"25%",

        });


         var intime=parseInt(inlabel.text);
         var outime=parseInt(outlabel.text);

         var time=intime-outime;

        var timelabel=Ti.UI.createLabel({

              text:time,              
              font:{fontSize:13}
        });

        timeview.add(timelabel);



        var noteview=Ti.UI.createImageView({                
            image:'TaskNote.png',
            width:"15%",

        });             


        noteview.addEventListener('click',function(e){

                    var tasknotewindow=Ti.UI.createWindow({
                    backgroundColor:'white',
                    layout:'vertical',
                    url:'TimeTracker/tasknote.js'

                });

                tasknotewindow.starttime=e.inlabel.text;

                tasknotewindow.open();
        });                         

        var taskview=Ti.UI.createView({
            width:"25%",

        });

        tasklabel=Ti.UI.createLabel({
             text:"Click",
             font:{fontSize:13},

        });


        //create window for task management
        var taskmanagewindow = Ti.UI.createWindow({
                    backgroundColor: 'white', layout: 'vertical',
                    url:'TimeTracker/task.js'
        }); 


        //Task Dialog Box
        taskoptionBox=Ti.UI.createOptionDialog({                            
                title:'Task',
                options:arrtaskname,
                buttonNames:['Cancel'],                     
         });

         taskoptionBox.addEventListener('click',function(e){                
             tasklabel.text= arrtaskname[e.index];                   
         });


        tasklabel.addEventListener('click',function(e){                 
                taskoptionBox.show();               
        });


        taskview.add(tasklabel);

        row1.add(inview);
        row1.add(outview);
        row1.add(timeview);
        row1.add(noteview);
        row1.add(taskview);         

        section.add(row1);
        data.push(section);
        table.setData(data);

}

1

1 Answers

1
votes

Check out this question/answer. Perhaps you will be able to accomplish your objective using this. I think you are both trying the same thing.

How to find or trace child click in tableviewrow (Titanium Studio)

This is how I've always accomplished this:

row1 = Ti.UI.createTableViewRow({
  layout:"horizontal",
  myval: intime // <=== Add your value here that you want to query for.
});
...
inlabel=Ti.UI.createLabel({
  text:intime,
  font:{fontSize:13}
});
inview.add(inlabel);
...

tableview.addEventListener('click', function(e){
  alert(e.rowData.myval);
});
...

// This section seems jumbled.  Should be something along the lines of the following...
// You have:
// section.add(row1);
// data.push(section);
// table.setData(data);
// Change to:
data.push(row1);
table.setData(data);
section.add(table);

Originally, I thought you wanted to manipulate the label inside the row, based on your comment that seems different now.