Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android 4 Application Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android 4 Application Development
This is the forum to discuss the Wrox book Professional Android 4 Application Development Reto Meier; ISBN: 978-1-1181-0227-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 4 Application Development 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 December 6th, 2012, 11:37 AM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Location: GRANADA Spain
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Why "final" in front of EditText?

in your sample ToDoList (page 111) we have

ListView myListView = (ListView) find....;
final EditText myEditText = (EditText) find...;

Why this EditText is made FINAL and not the ListView?

Maybe this is basic but I have done some research (with Schildt's book) and didn't find the answer

Thanks for your answer
Reply With Quote
  #2 (permalink)  
Old April 21st, 2013, 02:17 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Location: Netherlands
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

I also want to know more about this, this is the sole reason I registered on this website as I cannot find any other source on Google that explains this.
Reply With Quote
  #3 (permalink)  
Old April 21st, 2013, 05:22 PM
Authorized User
Points: 89, Level: 1
Points: 89, Level: 1 Points: 89, Level: 1 Points: 89, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
Default "final" in front of EditText

i guess that the reason of final has to do with "threading", but not in chapter 4,
but in chapter 8's todolist.
So i think that in the code of chapter 4 the use of final is not necessary, but in chapter 8 it is just safer to do so, as an (asynchronous) content provider is used in that todo list with his own thread, and i can imagine that the access to EditText from which the string is used to create a new record in the database is only safe when EditText is declared final.
So it might be that the author created the code with a content provider before he simplified to the code of chapter 4, and has left the "final" attribute
Reply With Quote
  #4 (permalink)  
Old April 22nd, 2013, 05:28 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Location: Netherlands
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Kees,

Thanks for responding so quickly, however I must say that my reason for questioning this is not because I do not know what the final keyword does but, simply put I am not sure if it has the same advantages as for Java compilers or if it as you just explained.

I posted this question on StackOverflow but I did not have enough points to include the pa4d tag. Here is the link: Are there (Performance) benefits of Views in Android that use the final keyword e.g final EditText?.

I am at Chapter 5 at the moment, I am going to read Chapter 8 so I can understand your explanation thoroughly before I post again. However, I think that it's best if the author himself comment on this to clarify since the final keyword has many advantages e.g full immutability for thread-safety and optimization by the compiler

Last edited by Android23Geek; April 22nd, 2013 at 08:19 AM..
Reply With Quote
  #5 (permalink)  
Old April 22nd, 2013, 07:22 AM
Authorized User
Points: 89, Level: 1
Points: 89, Level: 1 Points: 89, Level: 1 Points: 89, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 27
Thanks: 1
Thanked 0 Times in 0 Posts
Default "final" in front of EditText revisited

Hi,
My guess is not closer to the truth, as i checked Chapter_8_To-do_List with myEditText without the final, by declaring it as a class member in stead of a local variable, and it still run perfectly, i mean without runtime errors.
So the compiler error "Cannot refer to a non-final variable myEditText inside an inner class defined in a different method" seems to be the only reason to make it final. However i don't see that inner class here i must confess
Let's hope that Reto himself will clarify what the real benefits are!
Reply With Quote
  #6 (permalink)  
Old April 22nd, 2013, 08:16 AM
Authorized User
Points: 51, Level: 1
Points: 51, Level: 1 Points: 51, Level: 1 Points: 51, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Location: Netherlands
Posts: 14
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think I may have found the answer on StackOverflow:
link to possible answer.

We can't post pictures, if we could I would post a picture of where the inner class is and the method inside it. I deleted the final keyword and Eclipse showed me in
which inner class and method the problem originates. The inner class is View.OnkeyListener and the method is public boolean onKey. It would be wise to use
Chapter 4 To Do List Part 1 as I don't know how the code changes in Chapter 8.
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
not like the book in "Chaper 11"-"Ex11_01" Louaih83 BOOK: Ivor Horton's Beginning Visual C++ 2010 0 April 2nd, 2012 09:38 PM
MSXSL gives error message for "for" inside "select" ilyaz XSLT 1 December 9th, 2010 05:02 PM
How to theme the "Browse" button of "FileUpload" control? varunbwj BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 October 14th, 2009 01:22 AM
Add a CheckBox DataColumn to my DataGridView, Null format: "" or "True" but Error: F ismailc C# 2005 0 September 25th, 2009 04:56 AM
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM



All times are GMT -4. The time now is 02:46 AM.


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