Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
This is the forum to discuss the Wrox book Professional Android Application Development by Reto Meier; ISBN: 9780470344712
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 1st, 2009, 04:55 AM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default ToDo List setting the focus

With the ToDo List example, I would like to be able to set the focus to a particular item in the list, by code. For example I want to set the first item as highlighted automatically at the beginning, under program control. I have tried everything I can think off but not successful yet. Can anyone help please?
Reply With Quote
  #2 (permalink)  
Old June 1st, 2009, 04:53 PM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

The ToDoList example does automatically highlight the first item when the program starts, so I'm not sure what you mean there.

But if you want to modify the position of the highlight bar, try:

Code:
myListView.setSelection(pos);
Reply With Quote
  #3 (permalink)  
Old June 2nd, 2009, 12:59 AM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Sierawsk,

Further to my problem, I have successfully used
" myListView.setSelection0); " to position the place in the array list correctly.
That is part of my problem solved. The remaining part of the problem is that I have been unable to turn on the highlight at this position.
When I press the down key on the dpad the highlight turns on at the position I have set as outlined above. But when I try to use
" myListView.getSelectedItemPosition() " without manually highlighting the position first, the app crashes. That is why I want to highlight
an item by program control, to prevent such a crash. Thanks for your help so far. Is there any way to turn on the selection highlight?
Reply With Quote
  #4 (permalink)  
Old June 2nd, 2009, 08:46 AM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Sorry, but I'm still not clear on the problem you're having. My ToDo app starts up fine with the second (or any) item selected and highlighted.

I don't have to press the D-Pad to get the highlight bar to appear. And myListView.getSelectedItemPosition() doesn't cause a crash.

Are you making sure to set the list position after the list is fully populated? I placed this code at the very bottom of the onCreate() routine of ToDoList.java.
Reply With Quote
  #5 (permalink)  
Old June 2nd, 2009, 08:42 PM
Registered User
 
Join Date: May 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What version of the software are you using? I am using 1.0, I wonder could that be the difference.
Reply With Quote
  #6 (permalink)  
Old June 2nd, 2009, 10:17 PM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I'm using 1.1.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 Todo List removeItem abowman BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 4 February 5th, 2010 11:18 AM
Issues with Chapter 2 Todo List .add() on key listener Swak BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 2 January 22nd, 2010 06:43 AM
Setting the Focus sanderson Visual Basic 2008 Essentials 2 June 1st, 2009 06:32 PM
Chapter 4 Customising Your Todo List MMC2 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 0 May 12th, 2009 08:34 AM



All times are GMT -4. The time now is 05:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.