1

Hi I am trying to create a comment box and what I can't create is to display the message from the comment box on the actual screen not toasting it but storing it somehow. The idea is that I want to create a comment box and store+display the comments on the screen. What I have now is that I can just toast the comment.Is there any possible way of displaying the comments, and even if I re run the app the comment would still be there ? here is my code.

 public class commentbox extends Activity {

   private EditText edittext;

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

addKeyListener();
     }

  public void addKeyListener() {

// get edittext component
edittext = (EditText) findViewById(R.id.editText);

// add a keylistener to keep track user input
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {

    // if keydown and "enter" is pressed
    if ((event.getAction() == KeyEvent.ACTION_DOWN)
        && (keyCode == KeyEvent.KEYCODE_ENTER)) {

        // display a floating message
        Toast.makeText(commentbox.this,
            edittext.getText(), Toast.LENGTH_LONG).show();
        return true;

    } else if ((event.getAction() == KeyEvent.ACTION_DOWN)
        && (keyCode == KeyEvent.KEYCODE_9)) {

        // display a floating message
        Toast.makeText(commentbox.this,
            "Number 9 is pressed!", Toast.LENGTH_LONG).show();
        return true;
     }

    return false;
  }
      });
      }
       }
user3449550
  • 123
  • 5
  • 17

2 Answers2

0

There are multiple ways to do this. The easiest but least scalable is SharedPreferences.

The next would be saving to a file. Also not scalable.

The next, and best option, is through a sqlite db.

Here is more info:

How to save data in an android app

Community
  • 1
  • 1
Vic Vuci
  • 6,993
  • 6
  • 55
  • 90
0

you can use a textview with a handler to show it constantly.

and there are several options for storing data. i recommend shared preferences if you dont have too many Strings

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCsQFjAA&url=http%3A%2F%2Fdeveloper.android.com%2Freference%2Fandroid%2Fcontent%2FSharedPreferences.html&ei=KXI0U8uoJqmlsQSt14CwDA&usg=AFQjCNFyaMlF7pqBKbWPbXr7H1Wg4gKaoA&sig2=1SLoWt585FAo9pUSTxAumQ&bvm=bv.63808443,d.cWc

Technivorous
  • 1,682
  • 2
  • 16
  • 22