Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the index in an item of a list view #625

Open
Jtpatato21 opened this issue Jun 6, 2022 · 0 comments
Open

How to get the index in an item of a list view #625

Jtpatato21 opened this issue Jun 6, 2022 · 0 comments

Comments

@Jtpatato21
Copy link

Currently I use the class CachedView Model Cell Factory.createForFxmlView(MyView.class)
and I would like to know how I could get the getIndex method in my MyViewModel.class class
since if I use ListCell returns a value of -1

I would like how this can be used in a listView.

Item View:

public class MyView implements FxmlView<MyViewModel> {

 @FXML
 private Label lblIndex;
 @InjectViewModel
 private MyViewModel viewModel;

 public void initialize() {
  lblIndex.textProperty().bind(viewModel.getIndexProperty());
 }

}

Item ViewModel:

public class MyViewModel implements ViewModel {

 private final IntegerProperty indexProperty = new SimpleIntegerProperty();

 public MyViewModel(int index){
  indexProperty.set(index);
 }

 public IntegerProperty getIndexProperty() {
  return indexProperty;
 }

}

Example using ListCell in ViewModel

public class MyViewModel extends ListCell<T> implements ViewModel {

 private final IntegerProperty indexProperty = new SimpleIntegerProperty();

 public MyViewModel(){
  indexProperty.set(this.getIndex()); // getIndex return -1 value;
 }

 public IntegerProperty getIndexProperty() {
  return indexProperty;
 }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant