Blackberry ListField:如何为列表行单击添加监听器

时间:2011-07-11 05:43:01

标签: user-interface blackberry listfield

假设我有一个具有10个ListField的Screen类:

Vector v_prj_title,v_prj_mgr 

// v_prj_title contains name of projects

// v_prj_mgr contains name of the project_manager of  v_prj_title sequentially.

//Vector send_vector

//ListField myList

//ListCallBack callback

//It is clear from the code that in myList, I m inserting a vector send_vector ie  callback.insert(send_vector,i), which contains 2 strings collected one from v_prj_title and other from v_prj_mgr.


for(int i=0;i<10;i++)
{
    myList.insert(i);
    t1 = v_prj_title.elementAt(i).toString();
    send_vector = new Vector(2);
    send_vector.addElement(t1);
    t2 = v_prj_mgr.elementAt(i).toString();
    send_vector.addElement(t2);
    callback.insert(send_vector,i);
}

现在我对如何将eventListener添加到特定的ListField感到困惑,例如假设我单击第3个ListField,(假设这是下面显示的数据),应在第3个ListField中显示位图图片,并将项目名称(Project_Social_Meeting)和project_manager(Tom Clerk)插入数据库(SQlLite)

1. a. Project_Chat_Master( project name)

   b. Vyom Ryan (project manager)

2. a. Project_Online_Gaming

   b. Vivek Roy

3. a. Project_Social_Meeting

   b. Tom Clerk  
      .
      .
      etc.....

1 个答案:

答案 0 :(得分:1)

根据您的要求创建一个CustomField / Manager。(可能包含images / strings /...)

然后将它们添加到回调方法

例如:


步骤:1

//creating a custom field 
class MYListFieldItem extends Field
{
//@override
paint(graphics g)
{
g.drawbitmap(bitmap,0,0);
g.drawtext(string,bitmap.getwidth()+5<padding>,Math.min(bitmap.getHeight(),getFont().getHeight()));

//@override
layout(....)
{
setExtent(Math.min(width,bitmap.getwidth()+padding+getfont.getadvance(stringtext)),
Math.min(height,Math.min(bitmap.getHeight,getFont().getHeight())));
}
}

步骤-2: //创建列表项

MYListFieldItem [] fields[] = new MYListFieldItem [<numOfListItems>];
for(int i=0;i<fields.size;i++)
{
_callback = new MyListFieldCallBack();
_callback.insert(fields[i],i);
}

步骤-3:

//set listeners
mylistFielditem[i].setchangeListener(new fieldchangeListener(){
fieldChanged(field)
{
//do your action here.
});

//TIP: if the fields are just strings,
//@override
navigationclick()
{
if(status == keypadlistener.status_fourway)
{
MYListFieldItem  fld = (ListField)getLiefFieldwithFocus();
//do your coding 

}
}