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 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 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 March 14th, 2010, 09:00 PM
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default To Do list chapter one

****edit I meant chapter 2****

Eclipse is telling me that Edit Text is an invalid type :?
Code:

package com.paad.TodoList;

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


public class TodoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Get references to UI widgets
        ListView myListView = (ListView)findViewById(R.id.myListView);
        final EditText = (EditText)findViewById(R.id.myEditText);
        final ArrayAdapter<String> todoItems = new ArrayList<String>();
        final ArrayAdapter<String> aa;
        aa = new ArrayAdapter<String>(this,
        							  android.R.layout.simple_list_item_1,
        							  todoItems);
        myListeView.setAdapter(aa);
        myEditText.setOnKeyListener(new OnKeyListener() {
        	public boolean onKey(View v,int keyCode, KeyEvent event){
        	if (event.getAction() == KeyEvent.ACTION_DOWN)
        		if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        			todoItems.add(0, myEditText.getText().toString());
        			aa.notifyDataSetChanged();
        			myEditText.setText("");
        			return true;
        		}
        	return false;
        }
    });
}
        
        
        
    
}
Reply With Quote
  #2 (permalink)  
Old March 14th, 2010, 09:04 PM
Friend of Wrox
 
Join Date: Dec 2008
Location: , , .
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

You missed the variable name after EditText.
Reply With Quote
  #3 (permalink)  
Old March 15th, 2010, 09:50 PM
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tyvm

:p
What a dumb mistake. Guess its true that you shouldn't program when your tired...
Reply With Quote
  #4 (permalink)  
Old March 17th, 2010, 10:05 PM
Registered User
 
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi I'm also on chapter 2 on the todo list but i'm getting a different error.
Eclipse is telling me that ListView, ArrayAdapter, and OnKeyListener cannot be resolved to a type.

Code:
package com.paad.todolist;

import java.util.ArrayList;

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

public class ToDoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Inflate your view
        setContentView(R.layout.main);
        
        // Get references to UI widgets
        ListView myListView = (ListView)findViewById(R.id.myListView);
        final EditText myEditText = (EditText)findViewById(R.id.myEditText);
        
        // Create the array list of to do items
        final ArrayList<String>	todoItems = new ArrayList<String>();
        
        // Create the array adapter to bind the array to the listview
        final ArrayAdapter<String> aa;
        aa = new ArrayAdapter<String>(this,
        							android.R.layout.simple_list_item_1,
        							todoItems);
        
        // Bind the array adapter to the listview
        myListView.setAdapter(aa);
        
        myEditText.setOnKeyListener(new OnKeyListener(){
        	
        	public boolean onKey(View v, int keyCode, KeyEVent event){
        		if (event.getAction() == KeyEvent.ACTION_DOWN)
        			if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
        				todoItems.add(0, myEditText.getText().toString());
        				aa.notifyDataSetChanged();
        				myEditText.setText("");
        				return true;
        			}
        		return false;
        	}
        });
    }
}
Reply With Quote
  #5 (permalink)  
Old March 17th, 2010, 10:28 PM
Registered User
 
Join Date: Mar 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default import android.widget.ListView;

Quote:
Originally Posted by ojbux View Post
Hi I'm also on chapter 2 on the todo list but i'm getting a different error.
Eclipse is telling me that ListView, ArrayAdapter, and OnKeyListener cannot be resolved to a type.

Code:
package com.paad.todolist;

import java.util.ArrayList;

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

public class ToDoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // Inflate your view
        setContentView(R.layout.main);
        
        // Get references to UI widgets
        ListView myListView = (ListView)findViewById(R.id.myListView);
        final EditText myEditText = (EditText)findViewById(R.id.myEditText);
        
        // Create the array list of to do items
        final ArrayList<String>	todoItems = new ArrayList<String>();
        
        // Create the array adapter to bind the array to the listview
        final ArrayAdapter<String> aa;
        aa = new ArrayAdapter<String>(this,
        							android.R.layout.simple_list_item_1,
        							todoItems);
        
        // Bind the array adapter to the listview
        myListView.setAdapter(aa);
        
        myEditText.setOnKeyListener(new OnKeyListener(){
        	
        	public boolean onKey(View v, int keyCode, KeyEVent event){
        		if (event.getAction() == KeyEvent.ACTION_DOWN)
        			if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
        				todoItems.add(0, myEditText.getText().toString());
        				aa.notifyDataSetChanged();
        				myEditText.setText("");
        				return true;
        			}
        		return false;
        	}
        });
    }
}
Did you try using control + shift + o to import the needed libraries such as :D
Code:
import android.widget.ListView;
Reply With Quote
  #6 (permalink)  
Old March 17th, 2010, 10:29 PM
Authorized User
 
Join Date: Mar 2010
Location: Baldwin Park, CA
Posts: 16
Thanks: 0
Thanked 1 Time in 1 Post
Default

import these

Code:
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
Reply With Quote
  #7 (permalink)  
Old March 17th, 2010, 10:43 PM
Registered User
 
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh cool. Hey thanks guys. that worked!
Reply With Quote
  #8 (permalink)  
Old November 14th, 2011, 08:41 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Still error...

Hi,
I am at chapter 2 also, but still get the error.
My code.

package com.example.todolist;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class Todo_List extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
// Inflate your view
setContentView(R.layout.main);
// Get references to UI widgets
ListView myListView = (ListView)findViewById(R.id.myListView);
final EditText myEditText = (EditText)findViewById(R.id.myEditText);

// Create the array list of to do items
final ArrayList<String> todoItems = new ArrayList<String>();
// Create the array adapter to bind the array to the listview
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
todoItems);
// Bind the array adapter to the listview.
myListView.setAdapter(aa);

myEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
{
todoItems.add(0, myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("");
return true;
}
return false;
}
});

}

}

What can be wrong?
The error I am receiving is:
Sorry!
The application Todo_List
(process com.example.
todolist) has stopped
unexpectedly. Please try again.
[Force close]

Regards, Fredrik.
Reply With Quote
  #9 (permalink)  
Old November 14th, 2011, 09:12 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Smile

Hi,
I found the problem.
Add:
super.onCreate(savedInstanceState);
after line:
public void onCreate(Bundle savedInstanceState) {
and it works fine

/Fredrik.
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
Chapter 2 To Do List errors louie2107 BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 5 March 23rd, 2011 08:56 AM
Chapter 3 - Email List daibhidh BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 6 December 4th, 2009 05:39 AM
Chapter 9 Enemies list won't populate - Help! idlespur BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 September 2nd, 2009 05:59 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 02:09 AM.


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