English 中文(简体)
在黑莓列表字段中动态添加项目
原标题:Add item dynamically in blackberry list field

我对黑莓非常新, 我想在列表视图中动态添加项目, 在列表字段中静态添加项目, 但我想要在列表字段中以动态方式添加一些项目, 我在这里的代码

列表后退。 java

import java.util.Vector;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;

public class ListCallBack implements ListFieldCallback{

private Vector listElements = new Vector();
public void drawListRow(ListField listField, Graphics graphics, int index,
        int y, int width) {
    // TODO Auto-generated method stub
    String text = (String)listElements.elementAt(index);
    graphics.drawText(text, 0, y, 0, width);
 // Draw a line separator above each field except the first one
    if (index != 0) {
        graphics.setColor(Color.BLACK);
        graphics.drawLine(0, y, width, y);
    时 时

时 时

public Object get(ListField listField, int index) {
    // TODO Auto-generated method stub
    return listElements.elementAt(index);
时 时

public int getPreferredWidth(ListField listField) {
    // TODO Auto-generated method stub
    return Display.getWidth();
时 时

public int indexOfList(ListField listField, String prefix, int start) {
    // TODO Auto-generated method stub
    return listElements.indexOf(listField);
时 时

public void insert(String toInsert, int index) {
    listElements.insertElementAt(toInsert, index);
时 时

public void erase() {
    listElements.removeAllElements();
时 时

时 时

和清单View.java

listItem = new ListField();
listCallBack =new ListCallBack();
listItem.setCallback(listCallBack);

listItem.insert(0);
listCallBack.insert("Can t Text Now Driving", 0);       
listItem.insert(1);
listCallBack.insert("Going to school", 1);    
listItem.insert(2);
listCallBack.insert("Picking Up the Kids", 2);
add(listItem);

谁能帮我?

问题回答

您可以在 ListField 对象上调用无效() 或无效(int 索引) 来验证更改。

// after calling insert(int index) call 
listItem.invalidate(index);

// and after calling erase call 
listItem.invalidate();

如果您想要向列表字段显示新项目, 请将项目添加到矢量( 在您的情况下, 添加到列表元素中), 然后在列表字段对象中调用与增加的矢量大小相同的设定大小( ) 方法 。

listItem.setSize(listElements.size());

您不直接将项目添加到列表字段中。您会将其添加到您的收藏或阵列中。每当绘图列表被调用为一行时,它会读取从收藏中获取的数据并自成一体。

所以简单做以下步骤,

listElements.add(Object);

listItem.setSize(listElements.size());

您可以在项目列表上呼吁无效 。

我希望我能给你一个想法 这样你就可以找到一个方法...

如果你有任何疑问请通知我





相关问题
Android: SQLite and ListViews

Firstly, I have found many examples of how to grab data from a db and place it into a list, however this seems to be all for ListActivites. My list is part of the UI and therefore I can t use a ...

WPF synchronize Listview with some ViewCollection

I have a WPF ListView databound to an ObeservableCollection named FilteredAppendixes. Now I create a view with: CollectionViewSource.GetDefaultView(FilteredAppendixes); The CurrentItem property of ...

How to dynamically update a ListView on Android [closed]

On Android, how can I a ListView that filters based on user input, where the items shown are updated dynamically based on the TextView value? I m looking for something like this: -------------------...

How can I load a folders files into a ListView?

I d like to have a user select a folder with the FolderBrowserDialog and have the files loaded into the ListView. My intention is to make a little playlist of sorts so I have to modify a couple of ...

ListView Click event

I have a List of Items which I retrieved from my Sqlite DB... I want to set a Click event for each item. How I can customize this event based on the Item clicked???? Be descriptive... I am a beginner. ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

WPF ListView - is it better in Visual Studio 2010?

I ve tried implementing a readonly grid of items using the WPF ListView. It appears to me that this is a poorly designed and implemented control. (Unlike most of WPF which I like). Specific issues I ...

热门标签