2012-02-01 51 views
2

我使用下面的代碼來顯示豐富的列表。富媒體列表單擊事件

import net.rim.device.api.ui.*; 
import net.rim.device.api.ui.container.*; 
import net.rim.device.api.ui.component.*; 
import net.rim.device.api.system.*; 
import net.rim.device.api.ui.component.table.*; 

public class RichListDemo extends UiApplication 
{ 
public static void main(String[] args) 
{ 
    RichListDemo theApp = new RichListDemo();  
    theApp.enterEventDispatcher(); 
} 

public RichListDemo() 
{   
    pushScreen(new RichListScreen()); 
} 


private static class RichListScreen extends MainScreen 
{ 
    public RichListScreen() 
    { 
     super(Manager.NO_VERTICAL_SCROLL); 

     setTitle("Rich List Demo"); 

     add(new LabelField("BlackBerry Devices", LabelField.FIELD_HCENTER)); 
     add(new SeparatorField()); 

     Manager mainManager = getMainManager(); 

     RichList list = new RichList(mainManager, true, 2, 1); 

     Bitmap bitmap1 = Bitmap.getBitmapResource("9500.png"); 
     Bitmap bitmap2 = Bitmap.getBitmapResource("9000.png"); 

     list.add(new Object[] {bitmap1, "Device 1", "BlackBerry Smartphone 9500", "Description of Device 1."}); 
     list.add(new Object[] {bitmap2, "Device 2", "BlackBerry Smartphome 9000", "Description of Device 2."}); 
    } 
} 
} 

如何在Rich List中實現點擊事件?當我點擊列表時,我想顯示一個dilog框。可能嗎 ?。

回答

4

無法確定RichList中的選定行。如果您想要點擊功能,則可以使用TableView而不是RichListRichList應該用於只讀您要顯示的項目。如果您想捕獲輸入和/或允許用戶進行選擇,則應使用TableView

您可以使用this鏈接,創建一個表視圖和行

1

是有可能在增加點擊字段。請參閱以下代碼:

 final RichList list = new RichList(vfm, false,3, 1); 

     list.add(new Object[] {"jak się masz", "كيف حالك؟", "Description of Device 1." ,new SeparatorField()}); 
     list.add(new Object[] { "Device 2", "BlackBerry Smartphome 9000", "Description of Device 2.",new SeparatorField()}); 
     list.add(new Object[] { "Device 3", "BlackBerry Smartphome 9000", "Description of Device 3.",new SeparatorField()}); 
     list.add(new Object[] { "Device 4", "BlackBerry Smartphome 9000", "Description of Device 4.",new SeparatorField()}); 
     list.add(new Object[] { "Device 5", "BlackBerry Smartphome 9000", "Description of Device 5.",new SeparatorField()}); 
     list.add(new Object[] { "Device 6", "BlackBerry Smartphome 9000", "Description of Device 6.",new SeparatorField()}); 

     list.setFocusPolicy(TableController.ROW_FOCUS); 

    list.setCommand(new Command(new CommandHandler() 
    { 
     /** 
     * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata, Object) 
     */ 
     public void execute(ReadOnlyCommandMetadata metadata, Object context) 
     { 
     Dialog.alert("executed!"); 
     TableModel tableModel = list.getModel(); 
       Object[] objArray = (Object[])tableModel.getRow(list.getFocusRow());         
       int DISPLAY_NAME = 0; 
      Dialog dialog = new Dialog(Dialog.D_OK, (String)objArray[DISPLAY_NAME], 0, null, 0);   

       dialog.doModal();         

     } 
    }));