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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:25:20+00:00 2026-05-26T15:25:20+00:00

I am a total newbie when it comes to both java and android coding.

  • 0

I am a total newbie when it comes to both java and android coding. However, I am trying to piece together a simple notepad widget and app. It’s basically a widget which displays the note text in a textView and an activity which can be loaded by tapping the widget. In the activity I have an EditText and two buttons – one to save the note text and one to cancel and close the activity.

An example of note-text entered in the EditText could be:

Buy milk
Kiss girlfriend
Bother Snape

When I save my note data from the activity, it saves my note data to an internal storage file. It then updates the widget and here my note-text is shown WITH linebreaks. But if I then open my activity to edit the text it loads the note-text as a single line file and not a multiline file.

Do any of you guys have suggestions for what I could do to load my note-data as multiline text with linebreaks?

Here’s my activity code:

package dk.mfoller.android.basicnote;

import android.app.Activity;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RemoteViews;
import android.widget.Toast;
import android.widget.EditText;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import java.io.*;

public class BasicNoteActivity extends Activity {
/** Called when the activity is first created. */
private Button saveBtn;
private Button cancelBtn;
private EditText inputTxt;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Defines objects
    saveBtn = (Button) findViewById(R.id.basicNoteActivity_save); 
    cancelBtn = (Button) findViewById(R.id.basicNoteActivity_cancel);
    inputTxt = (EditText) findViewById(R.id.basicNoteActivity_input);

    // Calls a function to update/replace the displayed note text
    readNoteData();

    // Creates event handler for the save-button
    saveBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Calls a function to write to a file
            writeToFile();

            // Updates the displayed text in the widget
            String noteinput = inputTxt.getText().toString();
            RemoteViews views = new RemoteViews("dk.mfoller.android.basicnote", R.drawable.main_widget);
            views.setTextViewText(R.id.basicNoteWidget_notetext, noteinput);
            // Updates the actual widget - NOTE: This updates ALL instances of the widget
            ComponentName cn = new ComponentName(getBaseContext(), BasicNoteWidget.class);
            AppWidgetManager.getInstance(getBaseContext()).updateAppWidget(cn, views);


        }
    });

    // Creates event handler for the cancel-button
    cancelBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });

}

// A function to write to a file
protected void writeToFile() {
    String FILENAME = "basicNote_data";
    String noteinput = inputTxt.getText().toString();

    try {
        FileOutputStream fos = openFileOutput(FILENAME, MODE_PRIVATE);
        //noteinput.replace("\\r", "\n");
        fos.write(noteinput.getBytes());
        fos.close();

        // Displays a popup
        Toast.makeText(this, "Note saved!", Toast.LENGTH_SHORT).show();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

// A function to read from a file on load
protected void readNoteData() {
    String FILENAME = "basicNote_data";

    try {
        FileInputStream fis = openFileInput(FILENAME);
        InputStreamReader isr = new InputStreamReader(fis);
        BufferedReader br = new BufferedReader(isr);

        // How do I make this load as multiline text?!?!
        String line = null;
        String output = "";

        while((line = br.readLine()) != null) {
            output += line;
        }
        // Updates/replaces the displayed note text
        if(output != "") {
            inputTxt.setText(output);
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

Thanks in advance! ..oh, and please be very specific. Like I said: I’m a total newbie 🙂

  • 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-26T15:25:20+00:00Added an answer on May 26, 2026 at 3:25 pm

    The readLine() call does not include the end-of-line characters.

    Quickest solution is to change the read loop in readNoteData:

    while((line = br.readLine()) != null) {
        output += line + "\n";
    }
    

    You could also just read in the entire file and skip that step, but get this working first.

    See the BufferedReader.readLine() docs for info.

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

Sidebar

Related Questions

I'm a total newbie when it comes to CSS so I've pretty much given
Total newbie question but this is driving me mad! I'm trying this: myInt =
This is a total newbie question, so thanks in advance. I'm trying to get
I'm a total newbie when it comes to Javascript/jQuery so hopefully you can help
Total newbie to XPath and Java here. What I'm attempting to do is something
I'm a total newbie when it comes to SQL. I'm making a site in
I am a total jQuery newbie (well web coding newbie come to that) and
I am trying to use boost string algorithms for case insensitive search. total newbie
total newbie here. i was trying to replace a character in char * but
I'm a total newbie at PHP, but this seems so simple, there doesn't seem

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.