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 January 15th, 2012, 04:27 PM
Registered User
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question To Do List - Chapter 4

hej!

I wonder if somebody can help me with my littel probelm?
it's that when I run the first ToDo List in chapter 4 it will not work and just shutdown the program.

please do somebody know how to fix this problem?
 
Old January 25th, 2012, 03:29 PM
Registered User
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need to double check all your methods and variables.
Since you did not post your code it is not possible to see
where the actual error is.

Quote:
Originally Posted by alexh View Post
hej!

I wonder if somebody can help me with my littel probelm?
it's that when I run the first ToDo List in chapter 4 it will not work and just shutdown the program.

please do somebody know how to fix this problem?
 
Old January 27th, 2012, 02:52 PM
Registered User
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default the Code:

I have double check all my methods and variables. but I can't find something wrong whit it.
the code:


package com.paad.todolisttest;

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 Todolisttest extends Activity {

/** Called when the activity is first created. */
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);

final ArrayList<String> todoItems = new ArrayList<String>();
int resID = R.layout.todolist_item;
final ArrayAdapter<String> aa = new ArrayAdapter<String>(this, resID,
todoItems);
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;
}
});
}
}

code 2:


package com.paad.todolisttest;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

public class TodolisttestActivity extends TextView {

private Paint marginPaint;
private Paint linePaint;
private int paperColor;
private float margin;

public TodolisttestActivity (Context context, AttributeSet ats, int ds) {
super(context, ats, ds);
init();
}

public TodolisttestActivity (Context context) {
super(context);
init();
}

public TodolisttestActivity (Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

private void init() {
// Get a reference to our resource table.
Resources myResources = getResources();

// Create the paint brushes we will use in the onDraw method.
marginPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
marginPaint.setColor(myResources.getColor(R.color. notepad_margin));
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setColor(myResources.getColor(R.color.no tepad_lines));

// Get the paper background color and the margin width.
paperColor = myResources.getColor(R.color.notepad_paper);
margin = myResources.getDimension(R.dimen.notepad_margin);
}

@Override
public void onDraw(Canvas canvas) {
// Color as paper
canvas.drawColor(paperColor);

// Draw ruled lines
canvas.drawLine(0, 0, getMeasuredHeight(), 0, linePaint);
canvas.drawLine(0, getMeasuredHeight(),
getMeasuredWidth(), getMeasuredHeight(),
linePaint);

// Draw margin
canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginPaint);

// Move the text across from the margin
canvas.save();
canvas.translate(margin, 0);

// Use the TextView to render the text.
super.onDraw(canvas);
canvas.restore();
}

}

code layout xml main:

<?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/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New To Do Item"
/>
<ListView
android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

code layout xml todolist_item:

<?xml version="1.0" encoding="utf-8"?>
<com.paad.todolist.TodoListItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/notepad_text"
android:fadingEdge="vertical"
/>

code values xml colors:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="notepad_paper">#AAFFFF99</color>
<color name="notepad_lines">#FF0000FF</color>
<color name="notepad_margin">#90FF0000</color>
<color name="notepad_text">#AA0000FF</color>
</resources>

code values xml dimens:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="notepad_margin">30dp</dimen>
</resources>

code values xml strings:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, TodoList!</string>
<string name="app_name">Chapter 4 To-do List</string>
<string name="add_new">Add New Item</string>
<string name="remove">Remove Item</string>
<string name="cancel">Cancel</string>
</resources>

code values xml styles:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ToDoTheme" parent="@android:style/Theme.Black">
<item name="android:textSize">12sp</item>
</style>
</resources>





Similar Threads
Thread Thread Starter Forum Replies Last Post
To Do list chapter one WaJMHome BOOK: Professional Android 2 Application Development 8 November 14th, 2011 10:12 AM
Chapter 4 - To Do List solo BOOK: Professional Android 2 Application Development 1 June 15th, 2011 08:55 PM
Chapter 8 list view ios_immy BOOK: Beginning iOS 4 Application Development 4 February 10th, 2011 08:57 PM
Chapter 6 To Do List EricTapia BOOK: Professional Android 2 Application Development 0 April 14th, 2010 01:40 AM
Chapter 3 To do list question ttdevelop BOOK: Professional Android 2 Application Development 4 March 29th, 2010 11:18 PM





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