0

I have some trouble about using same text view with different text in same activity. I have Fragment called listGrade. In its onCreateView method I get

View rootView = inflater.inflate(R.layout.fragment_list_grade, container, false);    
TextView textViewww = (TextView) rootView.findViewById(R.id.Number);    
textViewww.setText(test1);    

What I want is that, create textView again from xml file and

textViewww.setText(test2);    

at the end my view has two textView with different text. How can I achieve?

fragment_list_grade.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/layout"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal|vertical"
    android:layout_width="match_parent"
    android:layout_marginTop="5dip"
    android:scrollbarStyle="outsideInset"
    android:fillViewport="true">

    <HorizontalScrollView
        android:id="@+id/horizontalView"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal|vertical"
        android:layout_width="wrap_content"
        android:layout_marginTop="5dip">

        <TableLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:id="@+id/tableLay"
           android:background="#ffffff">
<TableRow
    android:id="@+id/tableRow1"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <TextView
        android:id="@+id/Number"
        android:text="Row 2 column 1"
        android:layout_weight="1"
        android:background="#dcdcdc"
        android:textColor="#000000"
        android:padding="20dip"
        android:gravity="center"/>

    </TableRow>
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</LinearLayout>
guneraykut
  • 181
  • 14

2 Answers2

0

1) create a new xml layout and put your text in /* YOUR TEXT VIEW LAYOUT.xml */.

2) inflate your layout

    LinearLayout lt = (LinearLayout) findViewById( R.id./*YOUR TEXT VIEW CONTAINER*/ );
    TextView textViewww = (TextView) getLayoutInflater().inflate(R.layout./*YOUR TEXT VIEW LAYOUT.xml*/, null);
    textViewww.setText(test2);
    lt.addView(textViewww);
Rami
  • 7,879
  • 12
  • 36
  • 66
0

From what I understand, you will have multiple TextViews and you don't know the number because you are getting them from a web service.

The correct way of doing this, is through a ListView. The ListView gives you the ability to add as many elements of the same type you want. Just use android.R.layout.simple_list_item_1 as the row layout and then add each text into each new row.

Check this out for more info.

fcdimitr
  • 528
  • 3
  • 16
  • I must use tableView with 6 row and 7 column for each object which is returned from service. Thanks your advice =) – guneraykut Nov 12 '14 at 08:05