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

  • Home
  • SEARCH
  • 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 9080725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:08:22+00:00 2026-06-16T20:08:22+00:00

I have a simple app where I want to be able to save the

  • 0

I have a simple app where I want to be able to save the contents of a EditText control so the user to be able to add free format text and store it on a text file

I have the control in main.xml

<EditText
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="text in here"
        android:id="@+id/editText" android:layout_gravity="center"/>

And a menu item

<item android:id="@+id/menu_add"
      android:icon="@drawable/ic_menu_add"
      android:title="@string/menu_add"
      android:showAsAction="ifRoom|withText"
      android:onClick="addItem"
        />

With the onClick calling my addItem void

public void addItem(MenuItem menuItem) {

        String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath();

        try {
            FileWriter filenew = new FileWriter(sdcard + "/test.txt");
            BufferedWriter bw = new BufferedWriter(filenew);
            bw.write(menuItem.toString());
            bw.close();
        } catch (IOException e) {
            //You'll need to add proper error handling here
        }

    }

At the moment menuItem.toString() understandably just returns the string ‘Add’

How can I access the text contained in the EditText control so I can add that to the test.txt file?

  • 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-16T20:08:23+00:00Added an answer on June 16, 2026 at 8:08 pm

    Not sure how you’ve set up this app, but writing your data to the SD card is also probably not the best idea.

    Anyhow, you need to find your EditText first with (assuming you’re in an Activity which has the root layout set with setContentView):

    EditText mText = (EditText) this.findViewById(R.id.editText); 
    

    If you save that into a private variable, you can just use it across your Activity.
    You can take out the text with:

    mText.getText().toString(); 
    

    ps. You might also want to take a closer look at the way you’re getting the SD card path if you really want to stick with that. This will cause you some serious problems if someone doesn’t have an SD card mounted or when it is not reachable (per example if someone’s phone is connected with USB in certain cases).

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

Sidebar

Related Questions

I have a simple console app written in C#. I want to be able
I have a really simple Rails app. Basically an article with comments. I want
I'm working on a relatively simple Android app. I want it to have an
I have one simple app that suppose to get information from user and send
I have a simple app that will allow a user to tag a location.
I have a Core Data app with a fairly simple data model. I want
I have a simple Rails 3 blog app that needs an admin user so
Problem 1: I have a simple winforms app and I want to DataBind my
This is a real newbie question. I have simple app that selects a picture
I have simple Sinatra app. web.rb: require 'sinatra' get '/' do Hello end Gemfile:*

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.