Use slider as progress bar

Introduction : Progress bar generally used to display amount of work done on background, like displaying it while uplodaing or downloading any content. Titanium has Slider API which can be used to do the same for crossplatform application.

Description : Let me create a scenario where we will have a slider and a button on window. On click of that button, slider will progress, which will appear as progress bar on the screen.

//Define current window

var currentWin = Ti.UI.currentWindow;

//Define a button to strat the progress

var stratBtn = Ti.UI.createButton({

width : 200,

height : 50,

title : ‘Strat Progress’,

top : 300

});

 

//Button added to window

currentWin.add(stratBtn);

 

On above code block a window gets defined with a button added on it.

//Define a slider

var sliderAsProgressbar = Titanium.UI.createSlider({

width : 300,

min : 0, // Minimum value dispayed on the bar

max : 100 // Maximum value dispayed on the bar

});

 

//Set the thumb image with any transparent image

sliderAsProgressbar.thumbImage = ‘transparentImage.png’;

 

//Asign initial value to the bar

sliderAsProgressbar.value = 0;

//Disable slider for touch effect

sliderAsProgressbar.touchEnabled = false;

//Bar added to window

currentWin.add(sliderAsProgressbar);

Here on above a slider is added with the current window, which have a range from 0 to 100 to display.

Initially the slider value was set with 0. ( sliderAsProgressbar.value = 0; ). As we can touch the slider and change it value, we need to block this functionality to give a look and feel of progress bar. so ‘sliderAsProgressbar.touchEnabled = false;’ disable the touch over the slider.

Now lets define click event associated with the button, where onclick of this button slider will strat to increase its value and will look as progress bar.

//Event to start progress

stratBtn.addEventListener(‘click’, function(){

//Asign initial value to the bar

sliderAsProgressbar.value = 0;

var cahangedVal = 0, progressInterval;

//Check the progress interval

if (progressInterval) {

clearInterval(progressInterval);

}

//Do the progress stuff

progressInterval= setInterval(function() {

//Condition to check max value

if (val >= 101) {

//Stop the progressing

clearInterval(progressInterval);

 

//Asign initial value to the bar

sliderAsProgressbar.value = 0;

return;

}

//Change the bar value to show progress

sliderAsProgressbar.value = cahangedVal ;

cahangedVal++;

}, 1000);

});

Summarry : Here using above code block, I have described the way to use slider as progress bar. Now depending on the codition we can use it various place as progressbar implementation.

THAT’S IT

Advertisements

Video tutorial for counting total rows having different section with Alloy using Titanium

Introduction : Table view may contain different sections where each of those section may contain several rows.
Here I am describing the way to calculate total number of rows present in a tableview which have different section.

Code Block :

View : index.xml

Controller : Index.js

function showTotalRow(){
var allSection = $.tbl.data;
var totalRows = 0;
var count = 0;

for(count = 0; count < allsection.length; count++){
totalRows = allSection[count].rowCount;
}

alert('Total Rows : ' + totalRows);
}

Summary :
Now onwards easily we can get the total number of rows present on a table view with Alloy using Titanium.

THAT'S IT

Display red edit button on left side of rows in a table view using Alloy with Titanium

Introduction :
For IOS we can implement the row edit functionality in a table view.
Here I am describing the same with above video.

Code Block :

View : index.xml

Summary :
So here is the way I have described to display edit button along with red delete button on rows using Alloy with Titanium.

THAT’S IT

Rows drag and drop functionality in a table view using Alloy with Titanium

Introduction :
There might be a scenario where we need to re-arrange the rows with drag and drop effect. Using titanium, very easily we can achieve this.

Code Block :

View : index.xml

Summary :
Using above video I have described the way to implement drag and drop functionality on rows using Alloy with Titanium.

THAT’S IT

Video tutorial to display red delete button with Alloy using Titanium

Introduction :
Titanium provides you some APIs which are OS specific. One of the scenario is to display red delete button on swipe of row in a table view.
Using the above video, I am going to describe the way to display red delete button on swipe of rows on a table view.

Code Block :

View : index.xml

Summary :
Using above code on swipe of any row, you can display delete button on right side of row.

THAT’S IT

Remove all rows from a table view using Titanium with Alloy

Introduction :
There might be a scenario where we need to delete all rows from a table view. At this point also Titanium provides a way to meet our requirement.

Code Block :

View : index.xml

Controller : index.js

function removeRows(){

$.tbl.setData([]);

// OR $.tbl.data = [];
}

Summary :
Here we came to know about the way to delete all rows from a table view using Alloy with Titanium.

THAT’S IT

Video tutorial to delete specific row from a table view in Alloy using Titanium

Introduction :
As we can dynamically add rows to a table view, we can also delete a specific row from a table view.
Titanium provides ‘deleteRow’ method using which we can delete any row.

With the help of above video, I am going to describe the way to delete row.

Code Block :

View : index.xml

Controller : index.js

function deleteRow(event){

$.tbl.deleteRow(event.source);
}

Summary :
So using the above code block we can add the functionality to delete any specific row from a table view.

THAT’S IT