2013-02-27 86 views
0

當我將一個字符串列表傳遞給selectionCell時,第一個元素將被選作默認值,如何更改默認值?例如,在運行時,我想將index=i的項目看作默認值。SelectionCell中的默認選項

回答

0

沒有辦法設置的指數在細胞

您可以使用那裏只有字符串

SelectionCell statusOptionsCell = new SelectionCell(statusType); 
     Column<InvitedUser, String> statusColumn = new Column<Object, String>(
       statusOptionsCell) { 

      @Override 
      public String getValue(Object object) { 
       return object.getStatus(); //value set at runtime 
      } 
     }; 

如果你需要數組才使用

String[] myaaray= {"one","two","three"}; 



    SelectionCell statusOptionsCell = new SelectionCell(statusType); 
      Column<InvitedUser, String> statusColumn = new Column<Object, String>(
        statusOptionsCell) { 

       @Override 
       public String getValue(Object object) { 
        return st[1]; //pass integer as i here at runtime 
       } 
      }; 
0

選擇單元格在Cell小部件中。因此,讓我們以CellTable爲例。在單元格表中,每行對應於一個記錄,即模型/ POJO。每列對應於模型/ POJO中的一個屬性。因此,您的選擇單元格列應該綁定到模型中的一個屬性。

Set that property's value to whatever you want as a default value before supplying that model to the Cell Table

將模型的屬性設置爲全部單元表和公司的責任後,將值設置爲選擇單元格。

0

我有一個在運行時更改SelectionCell值的現實生活實例。我想要列出每行可執行的操作。選擇(並執行)動作後,我希望選擇回到它的默認值。

ArrayList<String> options = new ArrayList<String>(); 
options.add("Choose..."); 
options.add("Action 1"); 
options.add("Action 2"); 

final SelectionCell cell = new SelectionCell(options); 

Column<MyObject, String> column = new Column<MyObject, String>(cell) { 
    @Override 
    public String getValue(MyObject object) { 
     return null; 
    } 
}; 

column.setFieldUpdater(new FieldUpdater<MyObject, String>() { 
    @Override 
    public void update(final int index, MyObject object, String value) { 
     // perform selected action 
     // action name is stored in the `value` parameter 
     // ... 

     // back to default value 
     cell.clearViewData(object); 

     // ... or back to other value 
     // cell.setViewData(object, "Action 1"); 

     table.redrawRow(index); 
    } 
}); 

table.addColumn(column, "Test"); 

注意動作被鉤取上update方法,因此,如果選擇的值已改變了它只會解僱。它永遠不會被默認值觸發("Choose...")。