Listview 刷新/更新列表视图

Listview 刷新/更新列表视图,listview,titanium,refresh,updates,Listview,Titanium,Refresh,Updates,我有一个程序,它有一个listview,当用户单击项目时,详细信息视图打开,用户可以在其中编辑,当用户按下更新按钮时,当前窗口将关闭,listview将更新 这是我的代码: arr = [user1, user2, user3, user4]; var sections = []; var DataSection = Ti.UI.createListSection({ headerTitle : 'Data' }); DataSection.setItems(MyDataSet);

我有一个程序,它有一个listview,当用户单击项目时,详细信息视图打开,用户可以在其中编辑,当用户按下更新按钮时,当前窗口将关闭,listview将更新

这是我的代码:

arr = [user1, user2, user3, user4];

var sections = [];

var DataSection = Ti.UI.createListSection({
    headerTitle : 'Data'
});
DataSection.setItems(MyDataSet);
sections.push(DataSection);

myListView.setSections(sections);
myListView.addEventListener('itemclick', function(e) {
    var myWin = Titanium.UI.createWindow({
        backgroundColor : '#000'
    });
    var h_view = Titanium.UI.createView({
        backgroundColor : '#fff',
        layout : 'horizontal'
    });
    var userImg = Titanium.UI.createImageView({
        image : arr[e.itemIndex].getimage(),
        width : 100,
        height : 100
    });
    var v_view = Titanium.UI.createView({
        backgroundColor : '#fff',
        layout : 'vertical'
    });
    var nameLabel = Titanium.UI.createTextField({
        value : arr[e.itemIndex].getName(),
        color : '#000'
    });
    var mobileLabel = Titanium.UI.createTextField({
        value : arr[e.itemIndex].getMob(),
        color : '#000'
    });
    var labelAge = Titanium.UI.createTextField({
        value : arr[e.itemIndex].getage(),
        color : '#000'
    });
    var basicSwitch = Ti.UI.createSwitch({
        titleOn : 'Male',
        titleOff : 'Female'
    });
    basicSwitch.setValue(arr[e.itemIndex].getgender());
    var updateButton = Titanium.UI.createButton({
        text : 'update'
    });
    var index = e.itemIndex;
    updateButton.addEventListener('click', function(e) {

        arr[index].username = nameLabel.value;
        arr[index].setAge(labelAge.value);
        arr[index].setMob(mobileLabel.value);
        arr[index].setGender(basicSwitch.value);
          // I want to update the listview here
        myWin.close();
    });

    h_view.add(userImg);
    v_view.add(nameLabel);
    v_view.add(labelAge);
    v_view.add(mobileLabel);
    v_view.add(basicSwitch);
    v_view.add(updateButton);
    h_view.add(v_view);
    myWin.add(h_view);

    myWin.open();
});
win1.add(myListView);
编辑:

我试着用

 Titanium.UI.createRefreshControl({});
但我总是犯这个错误

Uncaught TypeError: Object #<UI> has no method 'createRefreshControl'
uncaughttypeerror:对象#没有方法“createRefreshControl”

您必须:首先获取您必须更新的项目,然后仅更新此项目

myListView.addEventListener('itemclick', function(e) {
     //get the item to be updated
     var user= e.section.getItemAt(e.itemIndex);
     //edit this user here
     user.name.text="Coyote";
     //then update the listview with the new data :
       e.section.updateItemAt(e.itemIndex, user); 
});

您必须:首先获取您必须更新的项目,然后仅更新此项目

myListView.addEventListener('itemclick', function(e) {
     //get the item to be updated
     var user= e.section.getItemAt(e.itemIndex);
     //edit this user here
     user.name.text="Coyote";
     //then update the listview with the new data :
       e.section.updateItemAt(e.itemIndex, user); 
});