开发者

Blackberry ListField: how to add Listener for list row click

开发者 https://www.devze.com 2023-03-19 12:10 出处:网络
Suppose i had a Screen class that has 10 ListField: Vector v_prj_title,v_prj_mgr // v_prj_title contains name of projects

Suppose i had a Screen class that has 10 ListField:

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);
}

Now I'm getting confused how to add eventListener to particular ListField, e.g. suppos开发者_StackOverflow社区e if I click the 3rd ListField,(suppose this is the displayed data below) a bitmap picture should be displayed in the 3rd ListField and the name of the project (Project_Social_Meeting) and project_manager (Tom Clerk) should be inserted into database (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.....


create a CustomField/Manager depending on your requirement.(which may contain images/strings/...)

then add them to the callback method

Ex:


step: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())));
}
}

step-2: //create list items

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

step-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 

}
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号