Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

android multiple textview in single row dynamically

 
Rohan Patel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am a newbie to android and i want to add multiple textviews in single row as
i have 1000's of objects to display like this manner

sample text 1 sample text 2
sample text 3 sample text 4
...
...
...

my layout look likes
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/catagory_linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
androidrientation="vertical" >



<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="266dp" >

<TableLayout
android:id="@+id/maintable"
android:layout_width="wrap_content"
android:layout_height="265dp"
android:shrinkColumns="*"
android:stretchColumns="*" >

<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>

</TableLayout>

</ScrollView>

</LinearLayout>


but don't know how to perform it dynamically
i stuck with it please help
thanks in adv
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think a table is a good view to use for this - precisely because it is not dynamic. You should look up ListView or its sibling the GridView and use that instead. You would create an Adapter that iterates over the values you want to display and creates the TextViews and assigns the values. By using an Adapter you can provide the data to / in the Adapter and have it provide the Views that will show up on the device. Since you want to have two TextViews per line, I would probably use the GridView, but the ListView is a bit more backwards compatible, so if you wanted the largest version coverage you might do a ListView and create your own extension of the ArrayAdapter which provides a LinearLayout with two TextViews side by side.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic