从它删除记录表清爽型适配器:黑莓 [英] Refreshing Table Model Adapter on deleting record from it : Blackberry

查看:238
本文介绍了从它删除记录表清爽型适配器:黑莓的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我米创造了黑莓表型号适配器。( ** 这是一个什么样的IM做的****)我已经添加按钮,字段和两个字符串。我M在字符串从vector.Now穿上按键数据点击我要删除对button.The数据的行从数据库中删除,但不会从屏幕视图中移除时按钮clicked.When我calld检索()函数调用更新的数据库,并再次绘制表格模型适配器....它添加以下旧表的新....不刷新它。是否有任何解决方案,以显示相同的表刷新的数据。

  mypackage的包;   进口java.util.Vector中;
   进口net.rim.device.api.system.Display;
   进口net.rim.device.api.ui.Color;
   进口net.rim.device.api.ui.Field;
   进口net.rim.device.api.ui.FieldChangeListener;
   进口net.rim.device.api.ui.Manager;
   进口net.rim.device.api.ui.XYRect;
   进口net.rim.device.api.ui.component.ButtonField;
   进口net.rim.device.api.ui.component.LabelField;
   进口net.rim.device.api.ui.component.table.DataTemplate;
   进口net.rim.device.api.ui.component.table.TableController;
   进口net.rim.device.api.ui.component.table.TableModelAdapter;
   进口net.rim.device.api.ui.component.table.TableView;
   进口net.rim.device.api.ui.component.table.TemplateColumnProperties;
   进口net.rim.device.api.ui.component.table.TemplateRowProperties;
   进口net.rim.device.api.ui.container.MainScreen;
   进口net.rim.device.api.ui.decor.BackgroundFactory;  公共final类自选扩展MainScreen实现FieldChangeListener
 {
私人DeviceTableModelAdapter _tableModel;
私人矢量_cities;
私有静态最终诠释NUM_ROWS = 1;
    私有静态最终诠释ROW_HEIGHT = 50;
    私有静态最终诠释NUM_COLUMNS = 3;
    公共ButtonField字段BTN;   公共自选画面(){
    超(Manager.NO_VERTICAL_SCROLL);    _cities =新的向量();
    _tableModel =新DeviceTableModelAdapter();    矢量样本=新的向量();
    sample.addElement(纽约);
    sample.addElement(NewDelhi);
    sample.addElement(新奥尔良);
    INT IK = 0;
       而(IK< sample.size())
       {
           字符串modelNumber = sample.elementAt(IK)的ToString();
           字符串MODELNAME =-Earth-;
           字符串NE =将String.valueOf(IK);
           [对象]行= {MODELNAME,modelNumber,NE};
           _tableModel.addRow(行);
           IK ++;
       }     TableView中的tableView =新的TableView(_tableModel);
         tableView.setDataTemplateFocus(BackgroundFactory.createLinearGradientBackground(Color.WHITE,Color.WHITE,Color.BLUEVIOLET,Color.BLUEVIOLET));
     TableController tableController =新TableController(_tableModel,的tableView);
     tableController.setFocusPolicy(TableController.ROW_FOCUS);
     tableView.setController(tableController);     //指定一个简单的数据模板显示3列
     DataTemplate中的DataTemplate =新的DataTemplate(的tableView,NUM_ROWS,NUM_COLUMNS)
     {
         公共字段[] getDataFields(INT modelRowIndex)
         {
             [对象]数据=(对象[])(_tableModel.getRow(modelRowIndex));
             现场[]栏= {getButtonFieldObject((字符串)数据[0]),新的LabelField((字符串)数据[1]),新的LabelField((字符串)数据[2])};
             返回领域;
         }
     };     dataTemplate.useFixedHeight(真);
     //定义区域,行高
     dataTemplate.setRowProperties(0,新TemplateRowProperties(ROW_HEIGHT));     的for(int i = 0; I< NUM_COLUMNS;我++)
     {
         dataTemplate.createRegion(新XYRect(I,0,1,1));
         dataTemplate.setColumnProperties(I,新TemplateColumnProperties(Display.getWidth()/ NUM_COLUMNS));
     }
     //将模板应用到视图     tableView.setDataTemplate(DataTemplate中);     添加(的tableView);
}
公共无效fieldChanged(场为arg0,ARG1 INT){/ *** tableView.DeleteAll(); **** /   / ****调用类再次与更新后的值再次*******绘制表模态适配器/}
私人最终静态类城市
{
    私人字符串_name;
    私人字符串_region;
    私人字符串_image;
    市(字符串名称,字符串区域,字符串图片)
    {
        _name =名称;
        _region =区域;
        _image =图像;
    }    公共字符串的getName()
    {
        返回_name;
    }
    公共字符串getRegion()
    {
        返回_region;
    }
    公共字符串的getImage()
    {
        返回_image;
    }
} 私有类DeviceTableModelAdapter扩展TableModelAdapter
    {
        公众诠释getNumberOfRows()
        {
            返回_cities.size();
        }
        公众诠释getNumberOfColumns()
        {
            返回NUM_COLUMNS;
        }
        保护布尔doAddRow(对象行)
        {
            [对象] arrayRow =(对象[])行;
            _cities.addElement(新城((字符串)arrayRow [0],(字符串)arrayRow [1],(字符串)arrayRow [2]));
            返回true;
        }
        保护对象doGetRow(INT指数)
        {
            市城市=(市)_cities.elementAt(指数);            [对象]行= {city.getImage(),city.getRegion(),city.getName()};            返回行;        }    }
 公共ButtonField字段getButtonFieldObject(字符串ARG){     BTN =新ButtonField字段(阿根廷,ButtonField.CONSUME_CLICK);
     btn.setChangeListener(本);
     返回BTN;
 }
     }


解决方案

你要考虑什么是黑莓表UI遵循MVC设计模式的事实。
因此,这意味着数据在模型更新。

例如像:

 对象是=(对象)是;
//获取附加到此视图的模型
TableModel的TM =(TableModel的)view.getModel();
//更新连接到该行的数据
tm.setElement(rowIndex位置,参数:columnIndex,是的);
tm.modelReset();

I m creating a Table Model Adapter in Blackberry.(**This is a sample what i m doing****)I have added button field and two Strings.I m putting data in String from vector.Now on button click i want to delete the row against button.The Data is deleted from the database but not removed from Screen view when button is clicked.When i calld the Retrieve() function to call updated database and draw the Table model adapter again....it is adding new Table below old one....not refreshing it. Is there any solution to show the refreshed data in same table.

    package mypackage;

   import java.util.Vector;
   import net.rim.device.api.system.Display;
   import net.rim.device.api.ui.Color;
   import net.rim.device.api.ui.Field;
   import net.rim.device.api.ui.FieldChangeListener;
   import net.rim.device.api.ui.Manager;
   import net.rim.device.api.ui.XYRect;
   import net.rim.device.api.ui.component.ButtonField;
   import net.rim.device.api.ui.component.LabelField;
   import net.rim.device.api.ui.component.table.DataTemplate;
   import net.rim.device.api.ui.component.table.TableController;
   import net.rim.device.api.ui.component.table.TableModelAdapter;
   import net.rim.device.api.ui.component.table.TableView;
   import net.rim.device.api.ui.component.table.TemplateColumnProperties;
   import net.rim.device.api.ui.component.table.TemplateRowProperties;
   import net.rim.device.api.ui.container.MainScreen;
   import net.rim.device.api.ui.decor.BackgroundFactory;

  public final class MyScreen extends MainScreen implements FieldChangeListener 
 {
private DeviceTableModelAdapter _tableModel;
private Vector _cities;
private static final int NUM_ROWS = 1;
    private static final int ROW_HEIGHT = 50;
    private static final int NUM_COLUMNS = 3;
    public ButtonField btn;

   public MyScreen(){
    super(Manager.NO_VERTICAL_SCROLL);

    _cities = new Vector();
    _tableModel = new DeviceTableModelAdapter();

    Vector sample =new Vector();
    sample.addElement("Newyork");
    sample.addElement("NewDelhi");
    sample.addElement("NewOrleans");
    int ik = 0;
       while(ik < sample.size())
       {
           String modelNumber = sample.elementAt(ik).toString();
           String modelName = "-Earth-";
           String ne = String.valueOf(ik);
           Object[] row = {modelName, modelNumber, ne};
           _tableModel.addRow(row);
           ik++;
       }

     TableView tableView = new TableView(_tableModel);
         tableView.setDataTemplateFocus(BackgroundFactory.createLinearGradientBackground(Color.WHITE, Color.WHITE, Color.BLUEVIOLET, Color.BLUEVIOLET));
     TableController tableController = new TableController(_tableModel, tableView);
     tableController.setFocusPolicy(TableController.ROW_FOCUS);
     tableView.setController(tableController);

     // Specify a simple data template for displaying 3 columns
     DataTemplate dataTemplate = new DataTemplate(tableView, NUM_ROWS, NUM_COLUMNS)
     {
         public Field[] getDataFields(int modelRowIndex)
         {
             Object[] data = (Object[]) (_tableModel.getRow(modelRowIndex));
             Field[] fields = {getButtonFieldObject((String)data[0]), new LabelField((String) data[1]), new LabelField((String) data[2])};
             return fields;
         }
     };

     dataTemplate.useFixedHeight(true);
     // Define regions and row height
     dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));

     for(int i = 0; i < NUM_COLUMNS; i++)
     {
         dataTemplate.createRegion(new XYRect(i, 0, 1, 1));
         dataTemplate.setColumnProperties(i, new TemplateColumnProperties(Display.getWidth() / NUM_COLUMNS));
     }
     // Apply the template to the view

     tableView.setDataTemplate(dataTemplate);

     add(tableView);
}
public void fieldChanged(Field arg0, int arg1) {

/***    tableView.DeleteAll();  ****/

   /**** calling Class again to draw the table Modal Adapter again with updated value *******/

}
private final static class City
{
    private String _name;
    private String _region;
    private String _image;
    City(String name, String region, String image)
    {
        _name = name;
        _region = region;
        _image = image;
    }

    public String getName()
    {
        return _name;
    }
    public String getRegion()
    {
        return _region;
    }
    public String getImage()
    {
        return _image;
    }
}

 private class DeviceTableModelAdapter extends TableModelAdapter
    {
        public int getNumberOfRows()
        {
            return _cities.size();
        }
        public int getNumberOfColumns()
        {
            return NUM_COLUMNS;
        }
        protected boolean doAddRow(Object row)
        {
            Object[] arrayRow = (Object[]) row;
            _cities.addElement(new City((String) arrayRow[0], (String) arrayRow[1], (String) arrayRow[2]));
            return true;
        }
        protected Object doGetRow(int index)
        {
            City city = (City) _cities.elementAt(index);

            Object[] row = {city.getImage(), city.getRegion(), city.getName()};

            return row;

        }

    }
 public ButtonField getButtonFieldObject(String arg){

     btn = new ButtonField(arg,ButtonField.CONSUME_CLICK);
     btn.setChangeListener(this);
     return btn;
 }
     }

解决方案

What you have to consider is the fact that Blackberry table UI follows the MVC design pattern. So it means that data are updated in the model.

Like for example:

Object yes = (Object)"Yes";
// gets the Model attached to this View
TableModel tm = (TableModel)view.getModel();
// updates the data attached to the row 
tm.setElement(rowIndex, columnIndex, yes); 
tm.modelReset();

这篇关于从它删除记录表清爽型适配器:黑莓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆