Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7169327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:58:00+00:00 2026-05-28T14:58:00+00:00

This is an todolist application that makes each item appear as if on a

  • 0

This is an todolist application that makes each item appear as if on a paper
pad(margin on the side & black line between items)
When i run the app, it does not show the entered text, but empty items are added to the list every time an entry is made. Also, the app works fine if todolistitemview isnt used in the array adapter construction.
This is my todolistactivity file:

package com.paad.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 TodolistActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        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
        int resID = R.layout.todolist_itemview;
        final ArrayAdapter<String> aa = new ArrayAdapter<String>(this, resID,
        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;
            }
            });
            }
}

This is my todolistitemview code:

package com.paad.todolist;
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 todolistitemview extends TextView{
    public todolistitemview(Context context){
        super(context);
        init();
    }
    public todolistitemview(Context context,AttributeSet ats){
        super(context,ats);
        init();
    }
    public todolistitemview(Context context,AttributeSet ats,int ds){
        super(context,ats,ds);
        init();

}
    private Paint marginpaint;
    private Paint linepaint;
    private int papercolor;
    private float margin;
    private void init(){
        Resources myresources=getResources();
        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.notepad_lines));
        papercolor=myresources.getColor(R.color.notepad_paper);
        margin=myresources.getDimension(R.dimen.notepad_margin);

    }

@Override
public void onDraw(Canvas canvas){
    canvas.drawColor(papercolor);
    canvas.drawLine(0, 0, getMeasuredWidth(), 0, linepaint);
    canvas.drawLine(0, getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight(), linepaint);
    canvas.drawLine(margin, 0, margin, getMeasuredHeight(), marginpaint);
    canvas.save();
    canvas.translate(margin,0);
}
}

These are the layout files-

main.xml-

<?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>

todolist_itemview.xml-

<?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="wrap_content"
android:padding="10dp"
android:scrollbars="vertical"
android:textColor="@color/notepad_text"
android:fadingEdge="vertical"
/>

Please help me resolve this issue. Any help is much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:58:01+00:00Added an answer on May 28, 2026 at 2:58 pm

    You didn’t copy the full code from the book. In your custom TextView onDraw() method, after the line:

    canvas.translate(margin,0);
    

    you must add:

    super.onDraw(canvas);
    canvas.restore();
    

    Without the call to the superclass onDraw() method your custom TextView will not draw the most important part , the text, that is why you actually get the paper drawing but no text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I'm writing an application that manages todo lists. Unlike 'traditional' todo list applications I
I'm using devise to handle my users and as part of my application each
This code: class Todo: def addto(self, list_name=, text=): Adds an item to the specified
I have a Priority class that has a datetime column. This column has a
I have a todo list in the database. Each Item has a todo item
I have my application entry point like this. /app/index.php <-- this is the main
I was just looking for a todolist service over the net. I encountered this
This is a piece of my code... def contactMaster(data=,url= str(chosenMaster)+todolist): print url: +url It
I can't seem to figure this out! I keep getting an error that says

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.