Android Dynamic TextView position -
i have data running query. so, need textview can add data dynamically.here code , allocate data dynamically in textview
do{ int count = cursor.getcount(); final textview[] mytextviews = new textview[count]; for(int counter = 0; counter<count ; counter++){ getname = cursor.getstring(cursor.getcolumnindexorthrow("name")); affiliation_id = cursor.getstring(cursor.getcolumnindexorthrow("number")); final textview rowtextview = new textview(this); rowtextview.settext(html.fromhtml(getname+"<sup><small>"+affiliation_id+"</small></sup><br/>")); rel.addview(rowtextview); } } while(cursor.movetonext()); it gives me result this.

as can see 1 word overlapping words. here xml file
<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillviewport="true" > <relativelayout android:layout_width="fill_parent" android:layout_height="match_parent" > <textview android:id="@+id/contopic" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:textappearance="?android:attr/textappearancesmall" /> <textview android:id="@+id/contitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/contopic" android:layout_margintop="22dp" android:text="medium text" android:textappearance="?android:attr/textappearancemedium" /> <relativelayout android:id="@+id/rel" android:layout_width="fill_parent" android:layout_height="match_parent" > </relativelayout> </relativelayout> </scrollview> so, need know or question
1) if want show text under contitle. should suppose ? 2) case 1, how can dynamically add desire position of textview , size of text. 3)if want add simple texview(normal text) under dynamically added textview.how can ?
and last thing, want achieve

you can use append method. have single textview , add textview layout. append new data , append \n new line.
also why have loop , while. while loop enough
textview tv = new textview(activityname.this); rel.addview(tv); if (cursor !=null && cursor.movetofirst()) { { getname = cursor.getstring(cursor.getcolumnindexorthrow("name")); affiliation_id = cursor.getstring(cursor.getcolumnindexorthrow("number")); tv.append(html.fromhtml(getname+"<sup><small>"+affiliation_id+"</small></sup><br/>")); tv.append("\n"); } while (cursor.movetonext()); }
Comments
Post a Comment