2016-06-15 50 views

回答

0

這很簡單。我建議你不要使用listview來實現它。只需在垂直方向上使用LinearLayout,並在單擊「添加更多」按鈕項時添加每個字段。

LinearLayout parentLayout = (LinearLayout) findViewById(R.id.parent_layout); //make sure you have set vertical orientation attribute on your xml 

TextView addMoreText = new TextView(context); 
addMoreText.setText("Add More"); 
addMoreText.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
     EditText editTextItem = new EditText(context); 
     parentLayout.addView(editTextItem, 0); 
     } 
}); 

parentLayout.addView(addMoreText); 

請注意,上面的代碼只是如何解決您的問題的全局圖片。對於在右側使用close或add按鈕的實現,您可以創建自定義視圖,該視圖可以保存您自己的EditText,ImageView。