1

Hello i am developing one app where i want to inflate layout in my Card view fro existing layout.And i want to show list of text view dynamically according to my string array.

Here is my existing layout

and i want to inflate following layout in last cardview of above layout

so tried with coding to do it but it display only one textview

my coding is as follows But it is not working it display only one textview i want to add textview dynamically according to my string size

I want to inflaate layout just like listview but i dont want to use listview.i want to implement this without listview dynamically

unknown apk
  • 147
  • 1
  • 10

2 Answers2

0

it display only one textview i want to add textview dynamically according to my string size

Probably due to inflating inflate_specification every time for each TextView and initializing container inside for-loop.

Do it as :

LinearLayout container = (LinearLayout)findViewById(R.id.temp);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().
                      getSystemService(Context.LAYOUT_INFLATER_SERVICE);

for(int i=0;i<5;i++)
  {  
     View view = inflater.inflate(R.layout.inflate_specification, container,false);
     // Create TextView
      TextView product = (TextView)view.findViewById(R.id.speci);
       product.setText("i= " + i);

       container.addView(view);
  }
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
0

Try this code:

LinearLayout container = (LinearLayout)findViewById(R.id.temp);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
container.removeAllViews();
for(int i=0;i<5;i++) {
    View view = inflater.inflate(R.layout.inflate_specification, container,false);
    // Create TextView
    TextView product = (TextView)findViewById(R.id.speci);

    product.setText("i= " + i);

    container.addView(view);

 }
Lokesh
  • 3,247
  • 2
  • 33
  • 62