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 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;
        }
    });
}
        
        
        
    
}
 
Old March 14th, 2010, 09:04 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

You missed the variable name after EditText.
 
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...
 
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;
        	}
        });
    }
}
 
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;
 
Old March 17th, 2010, 10:29 PM
Authorized User
 
Join Date: Mar 2010
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;
 
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!
 
Old November 14th, 2011, 09:41 AM
Registered User
 
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.
 
Old November 14th, 2011, 10:12 AM
Registered User
 
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.





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 06: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





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