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 8337743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:23:05+00:00 2026-06-09T04:23:05+00:00

Im making a simple programm for android, what can add, read and write text

  • 0

Im making a simple programm for android, what can add, read and write text lines into a txt file and show it on the List.
I got saveFile(); function what writes the todo_items Array to the file todo.txt.
But for some reason instead of showing the real text lines in the list it gives me numbers…
For example when i add “Feed dog, feed cat, feed fish, feed bird” and then Delete the 3d item in the result it gives me “0, 1, 2”. Have no clue why. Here is the code of the function

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           height="494" creationComplete="readFile()"
           >
<fx:Script>
    <![CDATA[
        public var intTemp:int;
        import mx.collections.ArrayCollection;
        [Bindable] public var todo_items:ArrayCollection;   
        private function readFile():void
        {
            var todoFile:File =File.applicationStorageDirectory.resolvePath("todo.txt");


                var fs:FileStream = new FileStream();
                fs.open(todoFile, FileMode.READ);
                var result:String = fs.readUTFBytes(fs.bytesAvailable);
                var items:Array = result.split("\n");
                items.pop();
                todo_items = new ArrayCollection(items);
                fs.close();

        }
        private function writeFile():void
        {
            var todoFile:File = File.applicationStorageDirectory.resolvePath("todo.txt");


            var fs:FileStream = new FileStream();
            fs.open(todoFile, FileMode.APPEND);


            fs.writeUTFBytes(task_txt.text + "\n");


            fs.close();
            readFile();
        }

        private function deleteItem():void
        {           
                var todoFile:File =File.applicationStorageDirectory.resolvePath("todo.txt");
                var fs:FileStream = new FileStream();
                fs.open(todoFile, FileMode.READ);
                var result:String = fs.readUTFBytes(fs.bytesAvailable);
                var items:Array = result.split("\n");
                items.pop();
                todo_items = new ArrayCollection(items);
                todo_items.removeItemAt(intTemp);
                fs.close();
                safeFile();
        }
        private function safeFile():void
        {

            var todoFile:File = File.applicationStorageDirectory.resolvePath("todo.txt"); 


            var fs:FileStream = new FileStream(); 
            fs.open(todoFile, FileMode.WRITE); 

            for(var item:String in todo_items)
            {
                fs.writeUTFBytes(item + "\n")
            }

            fs.close(); 
            readFile(); 



        }   

    ]]>
</fx:Script>


<s:List id="todo_list" left="10" right="10" top="142" bottom="87" dataProvider="{todo_items}"/>
<s:Button left="11" right="10" top="69" height="65" label="Save task" click="writeFile(); task_txt.text = null"
          enabled="{task_txt.text.length > 0}"/>
<s:TextInput id="task_txt" left="10" right="10" top="10" height="51" prompt="Specify a task"/>
<s:Button left="10" right="10" bottom="14" label="Delete"
          click="intTemp = todo_list.selectedIndex; todo_items.removeItemAt(todo_list.selectedIndex); deleteItem()"
          enabled="{todo_list.selectedIndex != -1}"/>


</s:Application>
  • 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-06-09T04:23:06+00:00Added an answer on June 9, 2026 at 4:23 am

    Well, for(var item in array) sets item to all the keys in the array, i.e. 0, 1, 2, …

    For getting the actual items, you need to do one of the following:

    for(var item:String in todo_items)
    {
        fs.writeUTFBytes(todo_items[item] + "\n")
    }
    

    or

    for each(var item:String in todo_items)
    {
        fs.writeUTFBytes(item + "\n")
    }
    

    I’d recommend the second because its cleaner.

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

Sidebar

Related Questions

I am making a simple program which suppose to accept txt file data from
I am new to android developement. I am making a simple expense management program
I'm making a simple program in Java. Given a set of letters it'll list
I'm making a simple program that maintains a list of numbers, and I want
Hey, im making a simple program that sends/receives files, my code sends text files
I am making an Android application. Since it is so simple, I first thought
I'm making a simple program that takes text entered in a text box, and
I was making a simple text field and 'send' button to display whatever the
I'm making a simple online store like program. What can you suggest that I
Ok, so I'm learning about ASP.NET by making a simple program to read in

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.