Alao Emmanuel
Alao Emmanuel

Reputation: 21

Getting Length of strings

I am building a simple Journal application that user can use to take notes. I am trying to get the list of journals from database in an activity. When I get it, it is displaying the whole note that the user had input. I just want to get the first line of words so that the user can click on it to get the full notes. Here is my code

This is where i save the code to database

    private void saveNoteToDB(View v) {
    Note note = new Note();
    String newNotes = enterNotes.getText().toString();
    note.setTheNotes(newNotes);
    //Save to Db
    db.addNotes(note);
    Snackbar.make(v, "Note Saved", Snackbar.LENGTH_LONG).show();
    new Handler().postDelayed(new Runnable()
    {
        @Override
        public void run()
        {
            alertDialog.dismiss();
            startActivity(new Intent(ListNotes.this, ListNotes.class));
        }
    }, 1500);
}

This is where i get items from the database

    //Get notes from Database
    noteItem = db.getAllNotes();
        for (Note c : noteItem) {
            Note note = new Note();
            note.setTheNotes(c.getTheNotes());
            note.setId(c.getId());
            note.setDateNotesAdded(c.getDateNotesAdded());

            listItem.add(note);
        }

    recyclerViewAdapter = new RecyclerViewAdapter(this, listItem);
    recyclerView.setAdapter(recyclerViewAdapter);
    recyclerViewAdapter.notifyDataSetChanged();
}

Upvotes: 0

Views: 98

Answers (2)

Vishal Sharma
Vishal Sharma

Reputation: 1063

note.setTheNotes(c.getTheNotes().substring(0,20) + "...." );

Use this for set the limit of string

Upvotes: -1

Ahsan Sohail
Ahsan Sohail

Reputation: 670

You can limit the string by using

note.setTheNotes(c.getTheNotes().substring(0,20) + "...." );

Note: 20 can be configurable number and may very in your case.

UPDATE : actually you want to do this when you are getting the data from DB.

Upvotes: 7

Related Questions