Mesith / android-binding

Automatically exported from code.google.com/p/android-binding
0 stars 0 forks source link

Can not bind command to component inside ListView #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In all the great demo, the template of ListView is too simple.  If there is any 
embed component in the template, such as Button or CheckBox. 

I can not found a good solution to bind such embeded component with any Command.

Can you provide some suggestion?

Original issue reported on code.google.com by laozhuan...@gmail.com on 23 Sep 2011 at 9:25

GoogleCodeExporter commented 9 years ago
In BindingSyntaxResolver.getObservableForModel, when binding the attribute of 
each embedded component, it is using the model as the arrayObservable. While as 
we know, it is not a good solution to add Command to this arrayObservable. 
Suggest to use the parent ViewModel.

I think it may be a enhancement need to take, since it is used frequently 

Original comment by laozhuan...@gmail.com on 23 Sep 2011 at 9:55

GoogleCodeExporter commented 9 years ago
Should I answer the first question? It is possible to bind command to ListView 
Child templates, as in the MusicPlayer Demo: 
http://code.google.com/p/android-binding/source/browse/Demos/trunk/MusicPlayer%2
0AndroidBinding%20Demo/src/com/gueei/demo/musicplayer/MusicListActivity.java 
(the demo is a bit old which is based on version 0.2 of AB, but the idea should 
work in 0.4)

For your second issue, I am not too sure what you mean, but I have to clarify:
When binding to ListView, the <ListView.../> is in the context of the main view 
model, while in the itemTemplate, the context is each individual items. As in 
the above demo, the 'per-item' command is added to the item itself, this is 
much more preferable than adding it to viewModel, since you need ways to 
reference to which particular row (in listView) of item. 

Original comment by gueei....@gmail.com on 24 Sep 2011 at 12:10

GoogleCodeExporter commented 9 years ago
Thanks so much for your quick response. Using your solution and fixed the 
problem. Greet!

Original comment by laozhuan...@gmail.com on 24 Sep 2011 at 8:51