假设我有一个Screen类,它有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);
}
现在我很困惑如何将eventListener添加到特定的ListField,例如,假设如果我单击第三个ListField,(假设这是下面显示的数据)位图图片应该显示在第三个ListField和项目的名称(Project_Social_Meeting)和project_manager (Tom Clerk)应该插入到数据库(SQlLite)
<>之前1. a. Project_Chat_Master(项目名称)b. Vyom Ryan(项目经理)2. 一。Project_Online_Gamingb. Vivek Roy3.一。Project_Social_Meetingb.汤姆·克拉克..等等……根据您的需求创建CustomField/Manager。(可能包含图像/字符串/…)
然后将它们添加到回调方法
,
步骤: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
}
}