问题描述
我已经试过这个链接创建listField为每个列表三lablefields row.but IAM无法看到列表字段items.but我可以说,listfield是导航点击added.because我能够得到listfield的选定索引。请人帮助亚姆在哪里做错了。codeI试图为...
公共类InboxWithOutCheckboxeslistfield扩展ListField实现ListFieldCallback {
私人矢量行;
私人TableRowManager排;
私人用户名的LabelField,信息,时间戳;
/ **
*创建一个新的自选对象
* /
公共InboxWithOutCheckboxeslistfield(){
// TODO自动生成构造函数存根 超级(0,ListField.MULTI_SELECT);
setRowHeight(80);
setCallback(本);
行=新的向量();
为(中间体X = 0; X小于10; X ++){
行=新TableRowManager();
用户名=新的LabelField(+将String.valueOf(X)
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.LEFT);
UserName.setText(名称);
row.add(用户名);
消息=新的LabelField(+将String.valueOf(X)
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Message.setText(辞海);
row.add(消息);
时间戳=新的LabelField(+将String.valueOf(X)
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Timestamp.setText(辞海);
row.add(时间戳);
rows.addElement(行); }
的setSize(rows.size());
} 公共无效drawListRow(ListField listField,图形显卡,INT指数,
INT Y,int width)将{
// TODO自动生成方法存根 InboxWithOutCheckboxeslistfield名单=(InboxWithOutCheckboxeslistfield)listField;
TableRowManager rowManager =(TableRowManager)list.rows.elementAt(指数);
rowManager.drawRow(图形,0,Y,宽度,list.getRowHeight()); } 公共对象获取(ListField listField,INT指数){
// TODO自动生成方法存根
返回null;
} 公众诠释的get preferredWidth(ListField listField){
// TODO自动生成方法存根
返回0;
} 公众诠释indexOfList(ListField listField,字符串preFIX,INT启动){
// TODO自动生成方法存根
返回0;
}
私有类TableRowManager扩展管理器{ 保护TableRowManager(){超级(0);
// TODO自动生成构造函数存根}
} 公共无效drawRow(图形显卡,诠释我,诠释Y,INT宽度,
INT的rowHeight){
// TODO自动生成方法存根
//安排此行管理器中的电池领域。
布局(宽,rowHeight时); //将其封闭列表中该行的经理。
setPosition两种(I,Y); //应用平移/裁剪变换图形
//上下文使得该行中的右侧区域涂料。
graphics.pushRegion(getExtent()); //绘制此经理的控制领域。
subpaint(图形); graphics.setColor(0x00CACACA);
graphics.drawLine(0,0,GET preferredWidth(),0); //恢复图形上下文。
graphics.popContext(); } 保护无效sublayout(INT宽度,高度INT){
// TODO自动生成方法存根
//设置大小和每个字段的位置。
INT fontHeight = Font.getDefault()的getHeight()。
INT preferredWidth = GET preferredWidth(); 场场= getfield命令(0); layoutChild(场,preferredWidth - 16,fontHeight + 1);
setPositionChild(场,34,3);
//设置列表名称标签字段
字段= getfield命令(1);
layoutChild(场,150,fontHeight + 1);
setPositionChild(场,34,fontHeight + 6); //设置适当的时候名称标签字段
字段= getfield命令(2);
layoutChild(场,150,fontHeight + 1);
setPositionChild(场,preferredWidth - 152,fontHeight + 6); setExtent(GET preferredWidth(),获得preferredHeight()); }
//行的preferred宽度由列表渲染限定。
公众诠释的get preferredWidth()
{ 返回的getWidth();
}
//行的preferred高度是如所定义的行高
//封闭列表。
公众诠释的get preferredHeight()
{
返回的getHeight();
} }
保护布尔navigationClick(INT的地位,诠释时间){
INT索引1 = getSelectedIndex();
的System.out.println(以下简称Clikced产品:+指数1);
返回true;
}
}
和MainScreen类是
公共类InboxWithOutCheckboxes扩展MainScreen { 私人InboxWithOutCheckboxeslistfield inboxWithOutCheckboxeslistfield; 公共InboxWithOutCheckboxes(){
超();
inboxWithOutCheckboxeslistfield =新InboxWithOutCheckboxeslistfield();
加(inboxWithOutCheckboxeslistfield);
添加(新SeparatorField());
}}
试试这个code -
在主屏幕添加名单 -
InboxWithOutCheckboxeslistfield InboxWithOutCheckboxeslistfield =新InboxWithOutCheckboxeslistfield();
加(InboxWithOutCheckboxeslistfield);
添加(新SeparatorField());
点击列表中的事件侦听器 -
保护布尔navigationClick(INT的地位,诠释时间){
的getValue();
返回true;
}
保护无效的getValue(){
域F = getFieldWithFocus();如果(F的instanceof ListField){
ListField L =(ListField)F; 最终诠释指数= l.getSelectedIndex(); FriendsRequestObject _contactslist =(FriendsRequestObject)FriendsRequest_fields.vector.elementAt(指数);
最后弦乐_name = _contactslist.getSender_name();
最后弦乐_id = _contactslist.getSender_id();
//Dialog.alert(_name); Application.getApplication()的invokeLater(Runnable的新(){
公共无效的run(){
Dialog.alert(_name);
}
});
// Dialog.alert(选择的元素是:+ Integer.toString(l.getSelectedIndex()));
}
}进口java.util.Vector中;
进口net.rim.device.api.ui.Color;
进口net.rim.device.api.ui.DrawStyle;
进口net.rim.device.api.ui.Field;
进口net.rim.device.api.ui.Font;
进口net.rim.device.api.ui.Graphics;
进口net.rim.device.api.ui.Manager;
进口net.rim.device.api.ui.component.LabelField;
进口net.rim.device.api.ui.component.ListField;
进口net.rim.device.api.ui.component.ListFieldCallback;类InboxWithOutCheckboxeslistfield扩展ListField实现ListFieldCallback {私人矢量接触;
静态矢量矢量=新的向量();私人INT contactslist_size = 0;私人字符串名_ =,ID_ =,状态_ =;公共InboxWithOutCheckboxeslistfield(){
超级(0,ListField.MULTI_SELECT);
setRowHeight(60);
setEmptyString(空单,DrawStyle.HCENTER);
setCallback(本); 接触=新的向量(); vector.addElement(新FriendsRequestObject(1,海1,));
vector.addElement(新FriendsRequestObject(2,HAI2,));
vector.addElement(新FriendsRequestObject(3,hai3,));
vector.addElement(新FriendsRequestObject(4,hai4,)); contactslist_size = vector.size(); 为(中间体X = 0; X&下; contactslist_size; X ++){ FriendsRequestObject B =(FriendsRequestObject)vector.elementAt(X); ID_ = b.getSender_id()的toString()。
名_ = b.getSender_name()的toString()。
状态:已= b.getimage()的toString()。 TableRowManager行=新TableRowManager(){
公共无效漆(图形G){
g.setBackgroundColor(Color.BLACK);
g.fillRect(0,0,的getWidth(),的getHeight());
g.setColor(Color.BLACK);
g.clear();
super.paint(G);
}
}; NAME1的LabelField =新的LabelField(ID_,DrawStyle.ELLIPSIS);
name1.setFont(Font.getDefault()获得(Font.PLAIN));
row.add(名称1); labelField属性名称=新的LabelField(名_,DrawStyle.ELLIPSIS);
name.setFont(Font.getDefault()获得(Font.PLAIN));
row.add(名); //添加到表
contacts.addElement(行);
} 的setSize(contacts.size());
}// ListFieldCallback实施
公共无效drawListRow(ListField listField,图形克,INT指数,诠释Y,int width)将{
InboxWithOutCheckboxeslistfield名单=(InboxWithOutCheckboxeslistfield)listField;
TableRowManager rowManager =(TableRowManager)list.contacts.elementAt(指数);
rowManager.drawRow(克,0,Y,宽度,list.getRowHeight());
}私有类TableRowManager扩展管理器{
公共TableRowManager(){
超级(0);
} //使此行的经理中的字段进行奠定了话
//画。
公共无效drawRow(图形克,INT X,INT Y,INT宽度,高度INT){
//安排此行管理器中的电池领域。
布局(宽,高); //将其封闭列表中该行的经理。
的setPosition(X,Y); //应用平移/裁剪变换图形
//上下文使得该行中的右侧区域涂料。
g.pushRegion(getExtent()); //绘制此经理的控制领域。
subpaint(G); g.setColor(0x00CACACA);
g.drawLine(0,0,GET preferredWidth(),0); //恢复图形上下文。
g.popContext();
} // Arrages这个经理的控制域由左到右内
//封闭表的列。
保护无效sublayout(INT宽度,高度INT){
//设置大小和每个字段的位置。
INT fontHeight = Font.getDefault()的getHeight()。
INT preferredWidth = GET preferredWidth(); / *在列表域的定位* /
// 状态
场场= getfield命令(0);
layoutChild(场,preferredWidth,50);
setPositionChild(场,10,5);
// 名称
字段= getfield命令(1);
layoutChild(场,150,fontHeight + 1);
// setPositionChild(场,1,2);
setPositionChild(场,80,fontHeight);
setExtent(preferredWidth,GET preferredHeight());
} //行的preferred宽度由列表渲染限定。
公众诠释的get preferredWidth(){
返回Graphics.getScreenWidth();
} //行的preferred高度是如所定义的行高
//封闭列表。
公众诠释的get preferredHeight(){
返回getRowHeight();
}}公共对象获取(ListField listField,INT指数){
返回null;
}公众诠释的get preferredWidth(ListField listField){
返回0;
}公众诠释indexOfList(ListField listField,字符串preFIX,INT启动){
返回0;
}}
FriendsRequestObject下面给出 -
公共类FriendsRequestObject {私人字符串SENDER_ID;
私人字符串SENDER_NAME;
私人字符串图像;公共FriendsRequestObject(字符串SENDER_ID,SENDER_NAME字符串,字符串图像){
this.sender_id = SENDER_ID;
this.sender_name = SENDER_NAME;
this.image =图像;
}公共字符串的getImage(){
返回形象;
}
公共无效setimage(字符串图像){
this.image =图像;
}公共字符串getSender_id(){
返回SENDER_ID;
}
公共无效setSender_id(字符串SENDER_ID){
this.sender_id = SENDER_ID;
}公共字符串getSender_name(){
返回SENDER_NAME;
}
公共无效setSender_name(字符串SENDER_NAME){
this.sender_name = SENDER_NAME;
}}
i have tried this link How to customize a list field in blackberry? to create the ListField with Three lablefields for every list row.but iam not able see the list field items.but i can say that listfield is added.because on navigation click i am able get the selected index of the listfield.please anybody help where iam doing mistake.The code i have tried is...
public class InboxWithOutCheckboxeslistfield extends ListField implements ListFieldCallback {
private Vector rows;
private TableRowManager row ;
private LabelField UserName,Message,Timestamp;
/**
* Creates a new MyScreen object
*/
public InboxWithOutCheckboxeslistfield() {
// TODO Auto-generated constructor stub
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setCallback(this);
rows = new Vector();
for (int x = 0; x < 10; x++) {
row = new TableRowManager();
UserName = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.LEFT);
UserName.setText("name");
row.add(UserName);
Message = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Message.setText("hai");
row.add(Message);
Timestamp = new LabelField("" + String.valueOf(x),
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT);
Timestamp.setText("hai");
row.add(Timestamp);
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
// TODO Auto-generated method stub
InboxWithOutCheckboxeslistfield list = (InboxWithOutCheckboxeslistfield) listField;
TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
rowManager.drawRow(graphics, 0, y, width, list.getRowHeight());
}
public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return null;
}
public int getPreferredWidth(ListField listField) {
// TODO Auto-generated method stub
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return 0;
}
private class TableRowManager extends Manager {
protected TableRowManager(){super(0);
// TODO Auto-generated constructor stub}
}
public void drawRow(Graphics graphics, int i, int y, int width,
int rowHeight) {
// TODO Auto-generated method stub
// Arrange the cell fields within this row manager.
layout(width, rowHeight);
// Place this row manager within its enclosing list.
setPosition(i, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
graphics.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(graphics);
graphics.setColor(0x00CACACA);
graphics.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
graphics.popContext();
}
protected void sublayout(int width, int height) {
// TODO Auto-generated method stub
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the list name label field
field = getField(1);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
// set the due time name label field
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(getPreferredWidth(), getPreferredHeight());
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth()
{
return getWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight()
{
return getHeight();
}
}
protected boolean navigationClick(int status, int time) {
int index1 = getSelectedIndex();
System.out.println("The Clikced item is:"+index1);
return true;
}
}
and the mainscreen class is
public class InboxWithOutCheckboxes extends MainScreen{
private InboxWithOutCheckboxeslistfield inboxWithOutCheckboxeslistfield;
public InboxWithOutCheckboxes(){
super();
inboxWithOutCheckboxeslistfield = new InboxWithOutCheckboxeslistfield();
add(inboxWithOutCheckboxeslistfield);
add(new SeparatorField());
}
}
Try This code -
Add lists on Main Screen-
InboxWithOutCheckboxeslistfield InboxWithOutCheckboxeslistfield = new InboxWithOutCheckboxeslistfield ();
add(InboxWithOutCheckboxeslistfield );
add(new SeparatorField());
Click event listener of list -
protected boolean navigationClick(int status, int time) {
getValue();
return true;
}
protected void getValue() {
Field f = getFieldWithFocus();
if (f instanceof ListField) {
ListField l = (ListField) f;
final int index = l.getSelectedIndex();
FriendsRequestObject _contactslist = (FriendsRequestObject) FriendsRequest_fields.vector.elementAt(index);
final String _name = _contactslist.getSender_name();
final String _id = _contactslist.getSender_id();
//Dialog.alert(_name);
Application.getApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert(_name);
}
});
// Dialog.alert("The selected element is: "+Integer.toString(l.getSelectedIndex()));
}
}
import java.util.Vector;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
class InboxWithOutCheckboxeslistfield extends ListField implements ListFieldCallback {
private Vector contacts;
static Vector vector = new Vector();
private int contactslist_size = 0;
private String name_ = "", id_="", status_="";
public InboxWithOutCheckboxeslistfield () {
super(0, ListField.MULTI_SELECT);
setRowHeight(60);
setEmptyString("Empty List", DrawStyle.HCENTER);
setCallback(this);
contacts = new Vector();
vector.addElement(new FriendsRequestObject("1", "hai1", ""));
vector.addElement(new FriendsRequestObject("2", "hai2", ""));
vector.addElement(new FriendsRequestObject("3", "hai3", ""));
vector.addElement(new FriendsRequestObject("4", "hai4", ""));
contactslist_size = vector.size();
for (int x = 0; x < contactslist_size; x++) {
FriendsRequestObject b = (FriendsRequestObject) vector.elementAt(x);
id_ = b.getSender_id().toString();
name_ = b.getSender_name().toString();
status_ = b.getimage().toString();
TableRowManager row = new TableRowManager() {
public void paint(Graphics g) {
g.setBackgroundColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
g.clear();
super.paint(g);
}
};
LabelField name1 = new LabelField(id_, DrawStyle.ELLIPSIS);
name1.setFont(Font.getDefault().derive(Font.PLAIN));
row.add(name1);
LabelField name = new LabelField(name_, DrawStyle.ELLIPSIS);
name.setFont(Font.getDefault().derive(Font.PLAIN));
row.add(name);
// add to the table
contacts.addElement(row);
}
setSize(contacts.size());
}
// ListFieldCallback Implementation
public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
InboxWithOutCheckboxeslistfield list = (InboxWithOutCheckboxeslistfield ) listField;
TableRowManager rowManager = (TableRowManager) list.contacts.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
// Causes the fields within this row manager to be layed out then
// painted.
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
// Place this row manager within its enclosing list.
setPosition(x, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
g.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
// Arrages this manager's controlled fields from left to right within
// the enclosing table's columns.
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
/* positioning of fields in list */
// Status
Field field = getField(0);
layoutChild(field, preferredWidth, 50);
setPositionChild(field, 10, 5);
// Name
field = getField(1);
layoutChild(field, 150, fontHeight + 1);
//setPositionChild(field, 1, 2);
setPositionChild(field, 80, fontHeight );
setExtent(preferredWidth, getPreferredHeight());
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
}
FriendsRequestObject is given below -
public class FriendsRequestObject {
private String sender_id;
private String sender_name;
private String image;
public FriendsRequestObject(String sender_id, String sender_name, String image){
this.sender_id = sender_id;
this.sender_name =sender_name;
this.image =image;
}
public String getimage() {
return image;
}
public void setimage(String image) {
this.image = image;
}
public String getSender_id() {
return sender_id;
}
public void setSender_id(String sender_id) {
this.sender_id = sender_id;
}
public String getSender_name() {
return sender_name;
}
public void setSender_name(String sender_name) {
this.sender_name = sender_name;
}
}
这篇关于在Listfield无法查看黑莓等领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!