0

I am using Layout inflator in my application to suit my requirements. I have text view, edittext and button in the layout. Here is my xml file

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

android:orientation="vertical">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textviewid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        />

    <EditText
        android:id="@+id/edittextid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


</LinearLayout>


<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/linearlayoutid"
    android:layout_centerHorizontal="true"
    android:text="button" />

I want to generate 'n' number of text views and pass the values from database. I used layout inflator here and below is my code

setContentView(R.layout.activity_main);

LinearLayout lv = (LinearLayout) findViewById(R.id.linearlayoutid);
View v = null;


for (int i = 0; i < 41; i++) {

    v = LayoutInflater.from(this).inflate(R.layout.activity_main, null);
    lv.addView(v);
}

//  EditText editText = (EditText) v.findViewById(R.id.edittextid);
final TextView[] myTextViews = new TextView[41];
for (int i = 0; i < 41; i++) {

    TextView tv = (TextView) v.findViewById(R.id.textviewid);
    d = mydb.getValues();

    myTextViews[i] = tv;
    tv.setText(d.get(i));
    Log.d(tag,"run"+d.get(i));

}

Its is generating 'n' number of text views dynamically but the problem is I am not able to display text using 'setText' . Its blank completely . Can anyone please tell me where I am making mistake? I want to pass the dynamic value and not the hard coded one. Any help would be great !! Thanks

Anusha
  • 939
  • 3
  • 13
  • 31

1 Answers1

0

If you want show list of some data, will be better to use List view. Or you can use RecyclerView. You can find more information about this layouts and how use it on Internet.

Alexander
  • 857
  • 6
  • 10