2017-02-16 8 views
0

スナップショットを既存のと、プログラムで同じ複数のLinearLayoutを追加するには(私はいくつかのTextViewとImageViewを子のLinearLayoutに追加しました);どのようにXMLを1つの

public class ListData extends AppCompatActivity { 
    LinearLayout childLL,parentLL; 
    TextView tName,tEmail,tCity; 
    ImageView iImage; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_list_data); 

    parentLL=(LinearLayout) findViewById(R.id.parentList); 
    childLL=(LinearLayout) findViewById(R.id.childList); 
    tName=(TextView) findViewById(R.id.listName); 
    tEmail=(TextView) findViewById(R.id.listEmail); 
    tCity=(TextView) findViewById(R.id.listCity); 
    iImage=(ImageView) findViewById(R.id.listImage); 

    for(int i=0;i<10;i++) { 
     //parentLL.addView(childLL); 
     //please Suggest code 
    } 
} 

} 
+0

使用recycleviewまたはリストビューの代わりに、forループ: ましょう新しいレイアウトファイルは、サンプル・コードは次のように可能性があり、child_layoutと呼ばれています – Pavya

答えて

1

childLayoutを別のレイアウトファイルに移動して手動で追加することができます。

LayoutInflater inflater = getLayoutInflater(); 
for (int i = 0, i < maxSize, i++) { 
    View v = inflater.inflate(R.layout.child_layout, null); 
    //customise your child view here if needed. 
    parentLL.addView(v); 
} 
関連する問題