Wrox Programmer Forums
|
BOOK: Professional Android 2 Application Development
This is the forum to discuss the Wrox book Professional Android 2 Application Development, 2nd Edition by Reto Meier; ISBN: 978-0-470-56552-0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android 2 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 3rd, 2011, 04:08 PM
Registered User
 
Join Date: Aug 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 5 ToDoList example code page 168

In the getView method on page 168, i changed the Linearlayout to RelativeLayout in the method since we are using a RelativeLayout.

It works fine but i wondered why the author used LinearLayout...

1. was it a mistake
2. It is more efficient to use LinearLayout
3. is relativelayout a 'special case' of linearlayout -is that why the previous version works?

Cheers.

Here's the code with Relativelayout used instead (works fine)


Code:
@Override
	  public View getView(int position, View convertView, ViewGroup parent) {
	    
		  RelativeLayout todoView;

	    ToDoItem item = getItem(position);

	    String taskString = item.getTask();
	    Date createdDate = item.getCreated();
	    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
	    String dateString = sdf.format(createdDate);

	    if (convertView == null) {
	      todoView = new RelativeLayout(getContext());
	      String inflater = Context.LAYOUT_INFLATER_SERVICE;
	      LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
	      vi.inflate(resource, todoView, true);
	    } else {
	      todoView = (RelativeLayout) convertView;
	    }

	    TextView dateView = (TextView)todoView.findViewById(R.id.rowDate);
	    TextView taskView = (TextView)todoView.findViewById(R.id.row);
	      
	    dateView.setText(dateString);
	    taskView.setText(taskString);

	    return todoView;
	  }
	}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 4 ToDoList Problem cythe BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 6 June 15th, 2011 09:53 PM
ToDoList Chapter 5 Line painting rich833 BOOK: Professional Android 2 Application Development 0 April 27th, 2011 09:28 AM
Chapter 2 - ToDoList Example srkrkalyan BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 January 22nd, 2011 01:09 PM
chapter 2 todolist kdpohl1 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 5 July 16th, 2010 03:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.