Separating text in one TextView by a line in Android -
i have textview
display stuff database. since don't know how generate number of textview
s according database, wonder if there way set visible line after 1 item string. example,
list of items book1 love total of 3 book2 love total of 2
as can see, if display in 1 textview
, hard determine separate books, wondering if there can separate them.
if put books name database in arraylist this
public arraylist<string> getallbooks(){ arraylist<string> alarraylist = new arraylist<string>(); database db = getwritabledatabase(); cursor cursor = db.query("books", null, null, null, null, null, null ); if (cursor!=null && cursor.movetofirst()) { do{ string book = cursor.getstring(cursor.getcolumnindex("book_name")); alarraylist.add(book); }while(cursor.movetonext()); db.close(); } return alarraylist; }
then can use arraylist create desire output
public void setbooks(){ arraylist<string> booknames = new yourdatabsename(this, version).getallbooks(); linearlayout layout = (linearlayout) findviewbyid(r.id.bookslayout); layoutparams textviewlayoutparams = new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content); textview heading = new textview(this); heading.settext("list of items"); heading.setlayoutparams(textviewlayoutparams); layout.addview(textview); if(booknames.size()>0){ for(int = 0; i<=booknames.size();i++){ textview book= new textview(this); book.settext("book "+ (i+1) +" "+booknames.get(i).tostring()); book.setlayoutparams(textviewlayoutparams); layout.addview(textview); } } textview footer= new textview(this); footer.settext("total of "+booknames.size()); footer.setlayoutparams(textviewlayoutparams); layout.addview(textview); }
now need linearlayout inside activitys layout this
<linearlayout android:id="@+id/bookslayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > </linearlayout>
Comments
Post a Comment