黑莓表视图 [英] Black Berry Table View

查看:156
本文介绍了黑莓表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的应用程序。如何添加于下表视图或网格。
我应该吸取的每一件事plz帮助
这是我的code

 导入net.rim.device.api.ui。*;
导入net.rim.device.api.ui.component。*;
导入net.rim.device.api.ui.container *。
net.rim.device.api.system数据导入*。
导入net.rim.device.api.util *。
进口的java.util。*;
/ *在用户输入数据的应用程序。显示此数据时,用户preSS保存按钮* /公共类显示扩展的UIApplication { / *声明字符串存储用户*的数据/ 字符串的getFirstName;
 串getLastName;
 串getEmail;
 串getGender;
 的getStatus串; / *声明文本字段用户输入* /
 私人AutoTextEditField的firstName; 私人AutoTextEditField lastName的; 私人EmailAddressEditField电子邮件;
/ *声明选择字段用户输入* /
 私人ObjectChoiceField性别;
 / *声明复选框栏供用户输入* /
 私人CheckBoxField字段的状态;
 //声明按钮领域
 私人ButtonField字段保存;
 关闭私人ButtonField字段;
 私人ButtonField字段列表;
 / *声明向量* /
 私有静态矢量_data;
 / *声明持久化对象* /
 私有静态持久性对象存储; / *创建一个切入点* /
公共静态无效的主要(字串[] args)
{  显示的obj =新显示();
  obj.enterEventDispatcher();}/ *创建默认构造函数* /
 公共显示()
 {  / *创建主屏幕类​​的一个目的是利用其功能* /
  MainScreen mainScreen =新MainScreen();  //主屏设置标题
  mainScreen.setTitle(新的LabelField(请输入您的数据));  //创建用户输入文本字段
  的firstName =新AutoTextEditField(名:,);
  lastName的=新AutoTextEditField(姓,);
  电子邮件=新EmailAddressEditField(电子邮件::,);  //创建用户输入的选择领域
  的String []项目= {男,女};
  性别=新ObjectChoiceField(性别,项目);
  //创建复选框栏
  状态=新CheckBoxField字段(激活,真正的);
  //创建按钮字段,添加使用监听功能
  保存=新ButtonField字段(保存,ButtonField.CONSUME_CLICK);
  save.setChangeListener(新FieldChangeListener()
  {
   公共无效fieldChanged(场场,诠释上下文)
   {
    保存();   }
  });
  关闭=新ButtonField字段(关闭,ButtonField.CONSUME_CLICK);
  close.setChangeListener(新FieldChangeListener()
  {
   公共无效fieldChanged(场场,诠释上下文)
   {
    的OnClose();
   }
  });
  名单=新ButtonField字段(列表,ButtonField.CONSUME_CLICK);
  List.setChangeListener(新FieldChangeListener()
  {
   公共无效fieldChanged(场场,诠释上下文){    pushScreen(新ListScreen());   }
  });
  //添加输入字段到主屏幕
  mainScreen.add(名字);
  mainScreen.add(lastName的);
  mainScreen.add(电子邮件);
  mainScreen.add(性别);
  mainScreen.add(状态);
  //添加按钮到主屏幕
  Horizo​​ntalFieldManager水平=新Horizo​​ntalFieldManager(Horizo​​ntalFieldManager.FIELD_HCENTER);
  horizo​​ntal.add(接近);
  horizo​​ntal.add(保存);
  horizo​​ntal.add(列表);
  mainScreen.add(水平);  //添加菜单项  mainScreen.addMenuItem(saveItem);
  mainScreen.addMenuItem(的getItem);
  mainScreen.addMenuItem(Deleteall);
  //主推屏
  pushScreen(mainScreen);
 }
 私人菜单项Deleteall =新菜单项(全部删除,110,10)
 {
  公共无效的run()
  {
   INT响应= Dialog.ask(Dialog.D_YES_NO,有U确保ü要删除整个数据库);
   如果(Dialog.YES ==响应){
   PersistentStore.destroyPersistentObject(0xdec6a67096f833cL);
   的OnClose();
   }
   其他
    Dialog.inform(感谢上帝);
  }
 };
//添加功能的菜单项saveItem
私人菜单项saveItem =新菜单项(保存,110,10)
{  公共无效的run()
  {
   //调用保存方法
   保存();
  }
};
//添加功能的菜单项saveItem
私人菜单项的getItem =新菜单项(GET,110,11)
{
 //正在运行的线程此菜单项
 公共无效的run()
 {
   //线程同步
   同步(存储)
   {
    //获取持久化对象的内容    _data =(向量)store.getContents();
    尝试{     对于(INT I = _data.size() - 1;我-1个;我 - )
     {      StoreInfo信息=(StoreInfo)_data.elementAt(I)
      //空对象检查
      如果(!_data.isEmpty())
      {
      //如果不为空
      //创建存储信息类的新对象
      在字符串中检索//存储信息
      的getFirstName =(info.getElement(StoreInfo.NAME));
      getLastName =(info.getElement(StoreInfo.LastNAME));
      getEmail =(info.getElement(StoreInfo.EMail));
      getGender =(info.getElement(StoreInfo.GenDer));
      的getStatus =(info.getElement(StoreInfo.setStatus));       //调用show方法
      显示();
      }     }
    }
    赶上(例外五){}
   }
  }
};
公共无效保存()
{ //创建内部类StoreInfo的对象
 StoreInfo信息=新StoreInfo();
 //获取在输入字段中输入的测试
 info.setElement(StoreInfo.NAME,firstName.getText());
 info.setElement(StoreInfo.LastNAME,lastName.getText());
 info.setElement(StoreInfo.EMail,email.getText());
 info.setElement(StoreInfo.GenDer,gender.toString());
 如果(status.getChecked())
  info.setElement(StoreInfo.setStatus,活动);
 其他
  info.setElement(StoreInfo.setStatus,在活动);
 //添加对象向量的端
 _data.addElement(信息);
 //同步线程
 同步(存储)
 {  store.setContents(_data);
  store.commit(); }
 //复位输入字段 Dialog.inform(成功!);
 firstName.setText(NULL);
 lastName.setText(NULL);
 email.setText();
 gender.setSelectedIndex(男);
 status.setChecked(真);
}
//编码持久化存储
静态的 {店内=
PersistentStore.getPersistentObject(0xdec6a67096f833cL);
同步(存储){
如果(store.getContents()== NULL){
store.setContents(新向量());
store.commit();
}
}
_data =新的向量();
_data =(向量)store.getContents();}
//类新的存储信息实现持久化
私有静态final类StoreInfo实现持久化
{
 //声明变量
 私人矢量_elements;
 公共静态最终诠释NAME = 0;
 公共静态最终诠释姓氏= 1;
 公共静态最终诠释的EMail = 2;
 公共静态最终诠释性别= 3;
 公共静态最终诠释setStatus = 4; 公共StoreInfo()
 {
  _elements =新的向量(5);
  的for(int i = 0; I< _elements.capacity(); ++ I)
  {
   _elements.addElement(新的String());
  }
 } 公共字符串getElement(INT ID)
 {
  返回(字符串)_elements.elementAt(ID);
 }
 公共无效setElement(INT ID,字符串值)
 {
  _elements.setElementAt(值,ID);
 }
}
//为展示方法的详细信息
公共无效显示()
{
 Dialog.alert(名称为+的getFirstName ++ getLastName +\\ nGender是+ getGender +\\ NE-邮件:+ getEmail +\\ n状态是的g​​etStatus +);
}
公共无效列表()
{ Dialog.alert(哈哈);
}//创建保存方法//重写的OnClose方法公共布尔的OnClose()
{
 System.exit(0);
 返回true;
} 类ListScreen扩展MainScreen
{
  字符串firstUserName =阿里;
  字符串lastUserName =阿西;
  字符串USEREMAIL =阿萨德;
  字符串userGender =asdasd;
  字符串userStatus =主动;
  私人AutoTextEditField USERFIRSTNAME;
  私人AutoTextEditField USERLASTNAME;
  私人EmailAddressEditField userMail;
  私人ObjectChoiceField usersGender;
  私人CheckBoxField字段usersStatus;
  私人ButtonField字段btnBack; 公共ListScreen()
 {
  SeparatorField SPS =新SeparatorField();
  Horizo​​ntalFieldManager HR =新HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER|HorizontalFieldManager.HORIZONTAL_SCROLLBAR);
  VerticalFieldManager VR =新VerticalFieldManager();
  的setTitle(新的LabelField(所有的数据列表));
  列表();
  btnBack =新ButtonField字段(返回,ButtonField.CONSUME_CLICK);
  btnBack.setChangeListener(新FieldChangeListener()
  {
   公共无效fieldChanged(场场,诠释上下文)
   {
    。UiApplication.getUiApplication()popScreen(getScreen());
   }
  });  hr.add(btnBack);  加(小时);
  加(SPS); }
公共无效列表() {
 _data =(向量)store.getContents();
 尝试{
  INT SN = 0;
  对(INT I = _data.size() - 1;我-1个; I - ,SN ++)
  {   StoreInfo信息=(StoreInfo)_data.elementAt(I)
   //空对象检查
   如果(!_data.isEmpty())
   {
   //如果不为空
   //创建存储信息类的新对象
   在字符串中检索//存储信息
    firstUserName =(info.getElement(StoreInfo.NAME));
    lastUserName =(info.getElement(StoreInfo.LastNAME));
    USEREMAIL =(info.getElement(StoreInfo.EMail));
    userGender =(info.getElement(StoreInfo.GenDer));
    userStatus =(info.getElement(StoreInfo.setStatus));    //调用listAll方法
   listAll();
   }  }
 }
 赶上(例外五){} }
 公共无效listAll()
 {
  SeparatorField SP =新SeparatorField();
  SeparatorField SPS =新SeparatorField();
  Horizo​​ntalFieldManager小时=新Horizo​​ntalFieldManager(Horizo​​ntalFieldManager.HORIZONTAL_SCROLL);
  hrs.add(新RichTextField(+ firstUserName ++ lastUserName +|+ USEREMAIL +|+ userGender +|+ userStatus));
  //添加(新RichTextField(电子邮件:+ USEREMAIL));
  //添加(新RichTextField(性别:+ userGender));
  //添加(新RichTextField(状态:+ userStatus));
  // SeparatorField SP =新SeparatorField();
  加(小时);
  加(SP);
  加(SPS);
 } 公共布尔的OnClose()
 {
  System.exit(0);
  返回true;
 }}
}


解决方案

有一个很好的 GridFieldManager 由安东尼·里兹克。

code:

 公共无效列表()
    {
        如果(空= MGRID和放大器;!&安培;!NULL = mGrid.getManager())
            。mGrid.getManager()删除(MGRID);
        INT列表ColWidth = net.rim.device.api.system.Display.getWidth()/ 4;
        MGRID =新GridFieldManager(新INT [] {0,列表ColWidth,列表ColWidth,
                列表ColWidth,列表ColWidth},VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
        mGrid.add(新NullField(可调焦));
        mGrid.add(新的LabelField(姓名));
        mGrid.add(新的LabelField(电子邮件));
        mGrid.add(新的LabelField(性别));
        mGrid.add(新的LabelField(激活));
        加(MGRID);
        _data =(向量)store.getContents();
        尝试{
            INT SN = 0;
            对(INT I = _data.size() - 1;我-1个;我 - ,SN ++){                StoreInfo信息=(StoreInfo)_data.elementAt(I)
                //空对象检查
                如果(!_data.isEmpty()){
                    //如果不为空
                    //创建存储信息类的新对象                    在字符串中检索//存储信息
                    firstUserName =(info.getElement(StoreInfo.NAME));
                    lastUserName =(info.getElement(StoreInfo.LastNAME));
                    USEREMAIL =(info.getElement(StoreInfo.EMail));
                    userGender =(info.getElement(StoreInfo.GenDer));
                    userStatus =(info.getElement(StoreInfo.setStatus));                    //调用listAll方法
                    mGrid.add(新NullField(可调焦));
                    mGrid.add(新的LabelField(firstUserName +
                            + lastUserName));
                    mGrid.add(新的LabelField(USEREMAIL));
                    mGrid.add(新的LabelField(userGender));
                    mGrid.add(新的LabelField(userStatus));
                }            }
        }赶上(例外五){
        }    }

另请参阅
黑莓网格布局管理器更新

here is my app. how to add table view or grids in the following. should i draw every thing plz help this is my code

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
import java.util.*;


/*An application in which user enters the data. this data is displayed when user press the save button*/



public class Display extends UiApplication {

 /*declaring Strings to store the data of the user*/

 String getFirstName;
 String getLastName;
 String getEmail;
 String getGender;
 String getStatus;

 /*declaring text fields for user input*/
 private AutoTextEditField firstName;

 private AutoTextEditField lastName;

 private EmailAddressEditField email;
/*declaring choice field for user input*/
 private ObjectChoiceField gender;
 /*declaring check box field for user input*/
 private CheckboxField status;
 //Declaring button fields
 private ButtonField save;
 private ButtonField close;
 private ButtonField List;
 /*declaring vector*/
 private static Vector _data;
 /*declaring persistent object*/
 private static PersistentObject store;

 /*creating an entry point*/
public static void main(String[] args) 
{

  Display obj = new Display();
  obj.enterEventDispatcher();



}

/*creating default constructor*/
 public Display() 
 {

  /*Creating an object of the main screen class to use its functionalities*/
  MainScreen mainScreen = new MainScreen();

  //setting title of the main screen
  mainScreen.setTitle(new LabelField("Enter Your Data"));

  //creating text fields for user input
  firstName = new AutoTextEditField("First Name: ", "");
  lastName= new AutoTextEditField("Last Name: ", "");
  email= new EmailAddressEditField("Email:: ", "");

  //creating choice field for user input
  String [] items = {"Male","Female"};
  gender= new ObjectChoiceField("Gender",items);
  //creating Check box field
  status = new CheckboxField("Active",true);
  //creating Button fields and adding functionality using listeners
  save = new ButtonField("Save",ButtonField.CONSUME_CLICK);
  save.setChangeListener(new FieldChangeListener()
  {
   public void fieldChanged(Field field, int context)
   {
    save();

   }
  });
  close = new ButtonField("Close",ButtonField.CONSUME_CLICK);
  close.setChangeListener(new FieldChangeListener()
  {
   public void fieldChanged(Field field, int context)
   {
    onClose();
   }
  });
  List = new ButtonField("List",ButtonField.CONSUME_CLICK);
  List.setChangeListener(new FieldChangeListener()
  {
   public void fieldChanged(Field field, int context){

    pushScreen(new ListScreen());



   }
  });
  //adding the input fields to the main screen
  mainScreen.add(firstName);
  mainScreen.add(lastName);
  mainScreen.add(email);
  mainScreen.add(gender);
  mainScreen.add(status);
  //adding buttons to the main screen
  HorizontalFieldManager horizontal = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
  horizontal.add(close);
  horizontal.add(save);
  horizontal.add(List);
  mainScreen.add(horizontal);

  //adding menu items

  mainScreen.addMenuItem(saveItem);
  mainScreen.addMenuItem(getItem);
  mainScreen.addMenuItem(Deleteall);
  //pushing the main screen
  pushScreen(mainScreen);
 }
 private MenuItem Deleteall = new MenuItem("Delete all",110,10)
 {
  public void run()
  {
   int response = Dialog.ask(Dialog.D_YES_NO,"Are u sure u want to delete entire Database");
   if(Dialog.YES == response){
   PersistentStore.destroyPersistentObject(0xdec6a67096f833cL);
   onClose();
   }
   else
    Dialog.inform("Thank God");
  }
 };
//adding functionality to menu item "saveItem" 
private MenuItem saveItem = new MenuItem("Save", 110, 10) 
{

  public void run() 
  {
   //Calling save method
   save();
  }
};
//adding functionality to menu item "saveItem" 
private MenuItem getItem = new MenuItem("Get", 110, 11) 
{
 //running thread for this menu item
 public void run() 
 {


   //synchronizing thread
   synchronized (store) 
   {
    //getting contents of the persistent object

    _data = (Vector) store.getContents();
    try{

     for (int i = _data.size()-1; i >-1; i--) 
     {

      StoreInfo info = (StoreInfo)_data.elementAt(i);
      //checking for empty object
      if (!_data.isEmpty()) 
      {
      //if not empty
      //create a new object of Store Info class






      //storing information retrieved in strings
      getFirstName = (info.getElement(StoreInfo.NAME));
      getLastName  = (info.getElement(StoreInfo.LastNAME));
      getEmail   = (info.getElement(StoreInfo.EMail));
      getGender   =  (info.getElement(StoreInfo.GenDer));
      getStatus  = (info.getElement(StoreInfo.setStatus));

       //calling the show method
      show();
      }

     }
    }
    catch(Exception e){}
   } 
  }


};
public void save()
{



 //creating an object of inner class StoreInfo
 StoreInfo info = new StoreInfo();
 //getting the test entered in the input fields
 info.setElement(StoreInfo.NAME, firstName.getText());
 info.setElement(StoreInfo.LastNAME,lastName.getText());
 info.setElement(StoreInfo.EMail, email.getText());
 info.setElement(StoreInfo.GenDer,gender.toString());
 if(status.getChecked())
  info.setElement(StoreInfo.setStatus, "Active");
 else
  info.setElement(StoreInfo.setStatus, "In Active");
 //adding the object to the end of the vector
 _data.addElement(info);
 //synchronizing the thread
 synchronized (store) 
 {

  store.setContents(_data);
  store.commit();



 }
 //resetting the input fields

 Dialog.inform("Success!");
 firstName.setText(null);
 lastName.setText(null);
 email.setText("");
 gender.setSelectedIndex("Male");
 status.setChecked(true);


}
//coding for persistent store
static {

store =
PersistentStore.getPersistentObject(0xdec6a67096f833cL);
synchronized (store) {
if (store.getContents() == null) {
store.setContents(new Vector());
store.commit();
}
}
_data = new Vector();
_data = (Vector) store.getContents();

}
//new class store info implementing persistable
private static final class StoreInfo implements Persistable 
{
 //declaring variables
 private Vector _elements;
 public static final int NAME = 0;
 public static final int LastNAME = 1;
 public static final int EMail= 2;
 public static final int GenDer = 3;
 public static final int setStatus = 4;

 public StoreInfo() 
 {
  _elements = new Vector(5);
  for (int i = 0; i < _elements.capacity(); ++i) 
  {
   _elements.addElement(new String(""));
  }
 }

 public String getElement(int id) 
 {
  return (String) _elements.elementAt(id);
 }
 public void setElement(int id, String value) 
 {
  _elements.setElementAt(value, id);
 }
}
//details for show method
public void show()
{
 Dialog.alert("Name is "+getFirstName+" "+getLastName+"\nGender is "+getGender+"\nE-mail: "+getEmail+"\nStatus is "+getStatus);
}
public void list()
{

 Dialog.alert("haha");


}

//creating save method

//overriding onClose method

public boolean onClose()
{


 System.exit(0);
 return true;
}

 class ListScreen extends MainScreen 
{


  String firstUserName="Ali";
  String lastUserName="Asif";
  String userEmail="assad";
  String userGender="asdasd";
  String userStatus="active";
  private AutoTextEditField  userFirstName;
  private AutoTextEditField  userLastName;
  private EmailAddressEditField  userMail;
  private ObjectChoiceField  usersGender;
  private CheckboxField usersStatus; 
  private ButtonField btnBack;

 public ListScreen()
 {
  SeparatorField sps = new SeparatorField();
  HorizontalFieldManager hr = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER|HorizontalFieldManager.HORIZONTAL_SCROLLBAR);
  VerticalFieldManager vr = new VerticalFieldManager();
  setTitle(new LabelField("List of All Data"));
  list();
  btnBack = new ButtonField("Back",ButtonField.CONSUME_CLICK);
  btnBack.setChangeListener(new FieldChangeListener()
  {
   public void fieldChanged(Field field,int context)
   {
    UiApplication.getUiApplication().popScreen(getScreen());
   }
  });

  hr.add(btnBack);



  add(hr);
  add(sps);

 }
public void list()

 {
 _data = (Vector) store.getContents();
 try{
  int sn=0;
  for (int i = _data.size()-1; i >-1; i--,sn++) 
  {

   StoreInfo info = (StoreInfo)_data.elementAt(i);
   //checking for empty object
   if (!_data.isEmpty()) 
   {
   //if not empty
   //create a new object of Store Info class






   //storing information retrieved in strings
    firstUserName = (info.getElement(StoreInfo.NAME));
    lastUserName = (info.getElement(StoreInfo.LastNAME));
    userEmail  = (info.getElement(StoreInfo.EMail));
    userGender   =  (info.getElement(StoreInfo.GenDer));
    userStatus  = (info.getElement(StoreInfo.setStatus));

    //calling the listAll method
   listAll();
   }

  }
 }
 catch(Exception e){}

 }
 public void listAll()
 {
  SeparatorField sp = new SeparatorField();
  SeparatorField sps = new SeparatorField();
  HorizontalFieldManager hrs = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLL);
  hrs.add(new RichTextField(""+firstUserName+" "+lastUserName+" | "+userEmail+" | "+userGender+" | "+userStatus));
  //add(new RichTextField("Email: "+userEmail));
  //add(new RichTextField("Gender: "+userGender));
  //add(new RichTextField("Status: "+userStatus));
  //SeparatorField sp = new SeparatorField();
  add(hrs);
  add(sp);
  add(sps);
 }

 public boolean onClose()
 {
  System.exit(0);
  return true;
 }

}
}

解决方案

There is a nice GridFieldManager by Anthony Rizk.

Code:

    public void list()
    {
        if (null != mGrid && null != mGrid.getManager())
            mGrid.getManager().delete(mGrid);
        int colWidth = net.rim.device.api.system.Display.getWidth() / 4; 
        mGrid = new GridFieldManager(new int[] { 0, colWidth, colWidth,
                colWidth, colWidth }, VERTICAL_SCROLL | VERTICAL_SCROLLBAR);
        mGrid.add(new NullField(FOCUSABLE));
        mGrid.add(new LabelField("Name"));
        mGrid.add(new LabelField("E-Mail"));
        mGrid.add(new LabelField("Gender"));
        mGrid.add(new LabelField("Active"));
        add(mGrid);
        _data = (Vector) store.getContents();
        try {
            int sn = 0;
            for (int i = _data.size() - 1; i > -1; i--, sn++) {

                StoreInfo info = (StoreInfo) _data.elementAt(i);
                // checking for empty object
                if (!_data.isEmpty()) {
                    // if not empty
                    // create a new object of Store Info class

                    // storing information retrieved in strings
                    firstUserName = (info.getElement(StoreInfo.NAME));
                    lastUserName = (info.getElement(StoreInfo.LastNAME));
                    userEmail = (info.getElement(StoreInfo.EMail));
                    userGender = (info.getElement(StoreInfo.GenDer));
                    userStatus = (info.getElement(StoreInfo.setStatus));

                    // calling the listAll method
                    mGrid.add(new NullField(FOCUSABLE));
                    mGrid.add(new LabelField(firstUserName + " "
                            + lastUserName));
                    mGrid.add(new LabelField(userEmail));
                    mGrid.add(new LabelField(userGender));
                    mGrid.add(new LabelField(userStatus));
                }

            }
        } catch (Exception e) {
        }

    }

See also BlackBerry Grid Layout Manager updated

这篇关于黑莓表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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