2013-01-17 69 views
0

我試圖動態地將editText添加到相對佈局。該版面已包含editText。我需要在現有的下面添加新的editText將Edittext動態添加到現有EditText下的相對佈局

EditText designation1 = new EditText(context); 
designation1.setHint("designation"); 
designation1.setSingleLine(true); 

和我的佈局是

layoutExp = 
    (RelativeLayout) childView.findViewById(R.id.relative_layout_edit_exp); 

和我現有的編輯文本是

designation = (EditText)childView.findViewById(R.id.editTextDesignatn); 
+0

你試過了嗎? – njzk2

回答

3

您需要使用RelativeLayout.LayoutParams和specifiy與addRule(RelativeLayout.BELOW, ...)的相對位置(這是編程等效android:below XML屬性):

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
params.addRule(RelativeLayout.BELOW, R.id.editTextDesignatn); 
layoutExp.addView(designation1, params); 
+0

thanx frnd .... thnks很多。 – Vikky

+0

我使用按鈕點擊動態添加文本框。但按鈕點擊僅對ist時間做出響應。第二次它永遠不會創建editText – Vikky

+0

它可能創建在相同的位置,這就是爲什麼你沒有看到它 – fiddler

0

如果您現有的EditText下設例如LinearLayout中這將是可能的。舉一個ID這個LinearLayout中,然後你可以把你的動態的EditText本的LinearLayout像

YourLinearLayout.addView(YourDynamicEditText);