trentrosenbaum (6) [Avatar] Offline
#1
I have just been working this the code in this example. I am running it against android 2.2. The code example under:

3.3.2 Technique 2: Putting the M in MVC with Android Adapters

Suggests that when a movie list item is tapped then the corresponding checkbox will be marked until the app in this state is restarted. This did not happen with the example. The list just show a tap on the item with the standard orange highlight and the checkbox remains unchecked. The following line was added to the example to create the behaviour that was suggested:

listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

This is because by default a ListView does not have a choice mode. At this stage in the book is this type of feedback useful?
trentrosenbaum (6) [Avatar] Offline
#2
Re: Feedback on section 3.3.2 Technique 2... with Android Adapters
Sorry I think my problem was with the sentence within the first paragraph of 3.3.3 where it reads:

"You can already tap an entry in the movie list, and it will even set the check mark."

This did not happen with the code presented before this sentence. So this caused me to think that maybe I have done something wrong. I went back through my code and the book and they were the same. It was only after I set the 'choice mode' that I got the above behaviour. Maybe this sentence needs to be altered.

I like it how the 'choice mode' is suggested at the end of the technique as a limited but useful approach.
charlie.collins (125) [Avatar] Offline
#3
Re: Feedback on section 3.3.2 Technique 2... with Android Adapters
Hi Trent.

First, all of this feedback is valuable and welcomed. Second, I didn't write this section of the book but I am working on a revisions/editing pass of it now, so I will look more closely at this section and see if we can clarify it.

Thanks for the input.
matthias.kaeppler (8) [Avatar] Offline
#4
Re: Feedback on section 3.3.2 Technique 2... with Android Adapters
Hi Trent,

I'm not sure if I understand your problem. Did the checkbox not change its state to checked/unchecked when tapping it before setting the choice mode? That shouldn't be, the choice mode is an orthogonal concept to what's actually presented in that technique (i.e. altering view state by changing the underlying model).

the adapter's getView() method is in this case responsible for setting a checkbox's checked state, depending on whether a movie is owned in the model backing the list. This should work entirely independent of the list's choice mode (which was only mentioned as a shortcut method to create lists that can manage selection state without defining an adapter).
charlie.collins (125) [Avatar] Offline
#5
Re: Feedback on section 3.3.2 Technique 2... with Android Adapters
I think it's just the "already" part of that sentence that Trent is saying is a bit confusing, because it doesn't work that way until later when you set the choice mode. The total example does work as described (but not if you are building it as you go along).

That's how I read this anyway, but please clarify if I am wrong.

thanks
matthias.kaeppler (8) [Avatar] Offline
#6
Re: Feedback on section 3.3.2 Technique 2... with Android Adapters
No, the choice mode has absolutely nothing to do with this, that's my point. Setting a choice mode is not mandatory (as Trent already mentioned, by default a list has no choice mode), and I only mention it on a side note as a shortcut for simple choice-style lists (because it allows one to maintain state without defining an adapter, see my previous post).

The code should work (and indeed does for me, at least the one I see in front of me in Eclipse) without having to define or handle the choice mode, so I don't really understand what the problem is. I will double check the source code listing against the project in SVN to see if I accidentally left out something important that's breaking it.
charlie.collins (125) [Avatar] Offline
#7
Re: Feedback on section 3.3.2 Technique 2... with Android Adapters
Ok, I haven't tried the code yet myself, I was just going by that sentence that he said maybe should be altered. I'll but out and pipe down until we have more clarification (and until I've gotten to that part myself).
trentrosenbaum (6) [Avatar] Offline
#8
Re: Feedback on section 3.3.2 Technique 2... with Android Adapters
Yes I think that is it, the use of the word 'already'.

After I had create the code in eclipse I read that sentence and thought that I had missed something. I could tap the list item but the check box did not become marked. I think because the sentence used the word already then I took that as meaning it should already do that. That is when I looked up the use of the choice mode. When I later read in the book about choice modes then I became confused.