questions on android and ios

You must Login before you can answer or comment on any questions.

Hey... i made a app in both ios and android....the view on the IOS is perfect but in android you cant see tge view...im using common js module..can i make a app that looks good in all android devices?? How can i fix the view to make it look good in android???thanks

— asked 10 months ago by Ronny Rodriguez
2 Comments
  • Missing from your question are a number of important pieces of information. I suggest you take a look at the Using Questions and Answers article, specifically the Q&A Question Checklist. The missing information is critical to reproducing problems in a test environment and often indicates other factors that cause the undesirable outcome you are experiencing.

    missing code samples, sdk

    — commented 10 months ago by Stephen Feather

  • sorry this is the sample code...im using titanium 2.0.2.GA..im trig to run the exact code in android . view.js

    win1 = function(color){
        //creating the view of the first window
     
    var view = Ti.UI.Android.createView({
        width:300,
        height:win1.height-310,
        left:10,
        top:10,
        backgroundColor:'#fff',
        borderRadius:5,
     
    });
    //creating the logo
    var logo = Titanium.UI.createImageView ({
                image:'69.jpg',
                width:253,
                height:96,
                left:0,
                top:0,
            }); 
        view.add(logo);
        //creating location1 button
        var button1 = Ti.UI.createButton({
        width:200,
        top:190,
         title:"Location # 1",
         backgroundSelectedColor:'red',
     
     
     
               font:{fontSize:26,fontWeight:'bold'},
     
    });
        button1.addEventListener('click', function(){
            var newWindow = Ti.UI.createWindow({
     
                backgroundColor : 'white',
                url:'location2.js'
     
            });
            newWindow.open();
    }); 
     
        view.add(button1);
        //creating location2 button
        var button2 = Ti.UI.createButton({
        width:200,
        top:240,
     
     
        title:'Location # 2',
     
     
               font:{fontSize:26,fontWeight:'bold'},
     
    });
     
     
    button2.addEventListener('click', function(){
            var newWindow = Ti.UI.createWindow({
                title : 'email',
                backgroundColor : 'white',
                url:'location1.js'
            });
            newWindow.open();
    });
     
    view.add(button2); 
    //creating location 3 button
    var button3 = Ti.UI.createButton({
        title : 'Location# 3',
        width:200,
        top:290,
        font:{fontSize:26,fontWeight:'bold'},
    });
     
     
     
    button3.addEventListener('click', function(){
            var newWindow = Ti.UI.createWindow({
                title : 'email',
                backgroundColor : 'white',
                url:'location3.js',
     
            });
            newWindow.open();
    });
    //adding the button
    view.add(button3); 
     
     
        return view
     
     
     
    };
     
    //exporting the module to main window
     
    module.exports = win1;
    app.js
    //creating tab group
    var tabGroup = Ti.UI.createTabGroup ();
     
     
     
     
    //creating main window
    var win = Ti.UI.createWindow({
     
        width:320,
        height:480,
        barImage:'navbar.png',
     
        title:'Mambo Style',
        backgroundColor:'blue',
        top:0,
        left:0,
    });
     
    //requiring module view into main wndow
     var mymodule = require('ui/view');
     var mymodule2 = new mymodule;
     
     win.add(mymodule2);
     
     
    //creating window 2
    var win1 = Ti.UI.createWindow({
     
        width:320,
        height:480,
        barImage:'navbar.png',
     
        title:'Mambo Style',
        top:0,
        left:0,
        url:'win2.js'
    });
     
     
    //creating window 3
    var win2 = Ti.UI.createWindow({
     
        width:320,
        height:480,
        barImage:'navbar.png',
     
        url:'win3.js',
        top:0,
        left:0,
    });
     
    //creating window 4
    var win3 = Ti.UI.createWindow({
     
        width:320,
        height:480,
        barImage:'navbar.png',
     
        url:'win.js',
        top:0,
        left:0,
    });
     
    //tab 1
    var tab1 = Ti.UI.createTab ({
            icon:'53-house.png',
            Title:'Home',
            window:win
        });
     
     
    //tab 2
            var tab2 = Titanium.UI.createTab ({
            icon:'86-camera.png',
            title:'Photos',
            window:win1
     
        });
     
     
        //tab 3
    var tab3 = Titanium.UI.createTab ({
            icon:'112-group.png',
            title:'Social',
            window:win2
     
        });
     
     
        //tab4
    var tab4 = Titanium.UI.createTab ({
            icon:'28-star.png',
            title:'More',
         window:win3
        });
     
    //adding all tab to tabgroup
    tabGroup.addTab(tab1);
          tabGroup.addTab(tab2);
           tabGroup.addTab(tab3);
           tabGroup.addTab(tab4);
     
           // tabgroup open
           tabGroup.open();

    — commented 10 months ago by Ronny Rodriguez

2 Answers

In line 3 of view.js, Ti.UI.Android.createView({ doesn't exist. Try Ti.UI.createView instead.

Though I'm not sure how that would have worked in iOS.

— answered 10 months ago by Adam Paxton
answer permalink
3 Comments
  • Yes..i did that on purpose to see if i can get the view to work i android....it works good in ios but in android nothing appears.have any odeahow i can develop for both?

    — commented 10 months ago by Ronny Rodriguez

  • Making up APIs probably won't be useful for you. The next thing I would check is the path on require('ui/view');, as last I checked, there were still some Jira tickets discussing platform disparity regarding absolute/relative paths and CommonJS specs.

    — commented 10 months ago by Adam Paxton

  • Whats wrong with my path???im i doing the commonjs wrong??

    — commented 10 months ago by Ronny Rodriguez

  1. You are using createWindow({url: }) and for this you are creating multiple contexts. It is adviced that you refactor it as

    var myUI = require('ui.js')
     
    var oWindow = myUI.createACustomWindow1(params)
    where in ui.js you would effectively have
    function createACustomWindow1(params)
    {
        var oWin = Ti.UI.createWindow(params)
        // add your settings and stuff here
    }
    exports.createACustomWindow1 = createACustomWindow1

  2. Why is there a Ti.UI.Android.createView ? I believe this is a chubby finger issue :P

  3. Android and iOS handle differently resources. Try refering to the full path just in case: '/src/cfg/img/myimage.png'

— answered 10 months ago by JC Guerrero
answer permalink
2 Comments
  • Hey jc..can you please update my code.to see what.you mean beacuase.im trying to figure it out

    — commented 10 months ago by Ronny Rodriguez

  • Sadly I'm not infront of my dev env so I couldn't ensure it would execute successfully. But it basically boils down on how you are splitting your code

    You are using windows definition in a different file, like

    var oWindow = Ti.UI.createWindow({url: 'somefile.js'})
    on somefile.js I'm assuming you have something like:
    win = Ti.UI.currentWindow
     
    var oButton = Ti.UI.createButton({label: 'Rock'})
        oButton.addEventListener( 'click', function() { //dosomething } )
     
    win.add(oButton)
    BUT, This creates 1 context (AKA process) for each window that uses that!!! Its a memory hugger and can't really share globals within but, there IS another way!

    move the creation of the window ALL TOGETHER to a function, like for example ui.js

    var exports = exports || {} // this allows us to either include or require
     
    funciton createComplexWindow(text)
    {
        var oButton = Ti.UI.createButton({label: text})
            oButton.addEventListener( 'click', function() { //dosomething } )
     
        var oWindow = Ti.UI.createWindow()
            oWindow.add(oButton)
    return oWindow
    }exports.createComplexWindow = createComplexWindow // this allows us to either include or require
    Then in your app.js file you can either have
    Ti.include('ui.js')
     
    oWin = createComplexWindow('Some text')
    or
    var ui = require('ui') // w/o the .js
     
    oWin = ui.createComplexWindow('Some text')
    and EVEN
    oWin = require('ui').createComplexWindow('Some text')
    Lastly if your views are not rendering properly its probablye because of the images not being queried accordingly. Check Ti.Filesystem to check if the file exists and use Ti.API.info to see the output

    — commented 10 months ago by JC Guerrero

Your Answer

Think you can help? Login to answer this question!