Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | 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 Display Modes
  #1 (permalink)  
Old December 30th, 2009, 02:09 AM
Registered User
 
Join Date: Dec 2009
Location: Southern California
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Chapter4:Clearable Edit Text example

Hi, I picked up the book a few weeks ago and slowly going through the material to build a good foundation.

I have previous experience with JavaScript, MEL, Cg, etc. but no "real" compiled programming language.

I'm wondering if this book is for me? I've had trouble with every example in the book. I've copied every line word for word and none of them worked on the first try. Possibly I'm missing the basics, things not explicitly in the tutorials (like to "import" classes when I use them, what to name files, creating extra Java files with new class extensions, etc). Debugging has been mostly trial and error, looking for spelling mistakes, and letting Eclipse suggest a fix, or looking at downloaded code(which is often different from the book's examples). I wish I knew a way to isolate errors...to print so that I can tell which part of the code is working. It's very hard to know what's failing/where. I end up butting my head against a wall looking for anything obvious -since I'm not experienced enough yet to know the fix.

I've managed to get through the examples to page 87(ClearableEditText example)...eventually getting them to work. But I'm stuck on that example.

My button seems to do nothing. I'm using the code from the wrox download package...so I think everything is right. Eclipse doesn't complain and my app runs on the emulator. But the button does nothing.

I even tried just putting in my command to change the text directly in the code:

editText.setText("Test Text");

Nothing. The "editText" field remains unchanged.

How can I tell if it's the views (the Button, the EditText?) or the function calling for the text to be cleared?

I can provide code, but it's basically the same as the downloaded code. If I can't get a function to attach to a button, I have no hope of ever making anything on android. I mean, that's as basic as it gets, right?

Code:
//ClearableEditText.java - the second java file in my src folder.

/**
 * Creating a new compound view by extending LinearLayout.
 * In this example the layout itself is defined as an external
 * resource {@link clearable_edit_text_view} which is inflated
 * within the constructor.
 */

package com.paad.todolist;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class ClearableEditText extends LinearLayout 
{

  EditText editText;
  Button clearButton; 

  public ClearableEditText(Context context) {
    super(context);

    // Get a reference to the LayoutInflater Service
    String infService = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater li = (LayoutInflater)getContext().getSystemService(infService);

    // Inflate the view from the layout resource
    li.inflate(R.layout.text_button_group_layout, this, true);

    // Get references to the child controls
   editText = (EditText)findViewById(R.id.editText);
   clearButton = (Button)findViewById(R.id.clearButton);
    
       
    // Hook up the functionality
    hookupButton();
  }
  
  private void hookupButton() {
	  clearButton.setOnClickListener(new Button.OnClickListener() {
	    
	    public void onClick(View v) {
	      editText.setText("");
	     
	    }
	  });
	}

}
Code:
//text_button_group_layout.xml - the layout file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<EditText
	android:id="@+id/editText"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="Enter custom text here..."
/>
<Button
	android:id="@+id/clearButton"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="Clear"
/>

</LinearLayout>
Code:
//TextButtonGroup.java - the first Java file containing my activity.

package com.paad.todolist;

import android.app.Activity;
import android.os.Bundle;

public class TextButtonGroup extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text_button_group_layout);
        }
}
-Vlad

Last edited by VladD; December 30th, 2009 at 02:20 AM. Reason: Adding in my code...
Reply With Quote
  #2 (permalink)  
Old March 14th, 2010, 08:29 PM
Registered User
 
Join Date: Mar 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am facing the same issue, can someone help please?
Reply With Quote
  #3 (permalink)  
Old April 20th, 2010, 09:01 AM
Registered User
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had the same issue.

I realized with the help of the debugger that no object of class ClearableEditText is created (set a breakpoint in the constructor). Looking again at the code I also didn't know where this ClearableEditText object is supposed to be created.

... some reading in the reference ... some educated guesses ...

So here we are: instead of

Code:
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.clearable_edit_text);
    }
it must be

Code:
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView( new ClearableEditText( getApplication() ) );
    }
Reply With Quote
  #4 (permalink)  
Old November 20th, 2012, 10:22 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom Control - ClearableEditText

I'm new to android development. When I do an <include> in my main.xml the hookbutton button on click listener does work. - is this the wrong way to implement the example in the book.

Thanks
Reply With Quote
Reply


Thread Tools
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
chapter4 coder123 BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 4 January 6th, 2010 04:19 AM
Chapter4, check RABARBAR BOOK: Beginning SQL 1 July 24th, 2008 01:46 PM
Read and Edit the text file stuartlittle C# 3 February 26th, 2008 04:35 AM
gettting data from gridview in edit mode text cont mahboob_sabir ASP.NET 2.0 Professional 1 May 8th, 2007 02:05 AM
Edit text in ListView control pavel Pro VB 6 4 September 29th, 2004 02:32 AM



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


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