當我點擊一個按鈕時,我想添加一個編輯文本字段到我的應用程序,但我不更改佈局。只需將它添加到由xml文件定義的現有一個之下。 可以說我有一個聯繫人應用程序,如果用戶需要添加額外的字段點擊按鈕並創建一個! 如何做到這一點?動態添加編輯文本
Q
動態添加編輯文本
-2
A
回答
1
你可以做的是在面板中使用EditText,即將它們分組在面板中,然後有一個按鈕,然後在按鈕上單擊創建一個EditText的實例並將其添加到相關面板。這樣你就不會限制自己只能添加一個面板,而是和用戶想添加的一樣多。
5
在佈局中保留一個EditText項並將其可見性設置爲不見了。
<EditText android:visibility="gone" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
然後單擊按鈕設置可見的onclick事件可見。
或
您可以以編程方式添加EditText項目。
將LinearLayout添加到您的xml中。
<LinearLayout
android:id="@+id/editTextGroupLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
在按鈕上單擊事件以編程方式添加EditText。
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.editTextGroupLayout);
EditText editTextView = new EditText(this);
editTextView.setGravity(Gravity.CENTER);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 1);
editTextView.setLayoutParams(params);
linearLayout.addView(editTextView);
希望這會有所幫助。
0
首先你要從web服務中調用數據。例如: description = Parser.getDescription;
在XML佈局:
<Button android:id="@+id/button" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:onClick="@string/ButtonClick"/>
<EditText android:id="@+id/note" android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
代碼:
ButtonName = (Button)findViewById(R.id.note);
Data = (EditText)findViewById(R.id.note);
public void ButtonClick(View v){
description = Parser.getDescription;
Data.settext(description);
}
相關問題
- 1. 單擊動態添加編輯文本
- 2. 編輯動態文本HTML
- 3. 富文本編輯器...動態添加類
- 4. 如何在android中動態添加和使用編輯文本?
- 5. 動態添加TinyMCE編輯器到文本框
- 6. HTML動態添加圖像到iframe(如文本編輯器)
- 7. 將編輯文本動態添加到佈局
- 8. 在對話框中添加動態編輯文本
- 9. 將動態圖像添加到編輯文本中
- 10. Android:動態添加線性佈局中的編輯文本框?
- 11. 動態編輯文本和文本框
- 12. 從線性佈局動態添加編輯文本中獲取文本
- 13. 動態添加一個tinymce編輯器
- 14. 動態添加編輯控件和靜態文本到對話框visual C++
- 15. 添加編輯或刪除編輯器Google動態分頁
- 16. 動態添加文本框
- 17. 添加TinyMCE的編輯器腳本jquery的動態
- 18. 動態簡單文本編輯器Java
- 19. 動態編輯表td文本
- 20. 動態TextWatcher ontextchange爲編輯文本
- 21. 如何動態編輯「noRowsToShow」文本?
- 22. Access 2010子文本編輯和添加
- 23. 添加2個textChangedListeners來編輯文本?
- 24. 動態添加文本框以動態添加面板
- 25. 添加按鈕,動態也添加文本框,動態AngularJS
- 26. 如何在單擊按鈕時動態添加編輯文本框?
- 27. 有沒有什麼辦法根據web服務動態添加編輯文本?
- 28. 我想編輯Eclipse中的自動文本添加功能
- 29. PyQt4 - 添加文本編輯區域動畫示例
- 30. 添加/編輯
是它TextField的有限數量的可打開?如果是這樣的話,你可以通過觸發buttonClick事件來看到這些轉向。 – AndroidHustle 2011-12-15 11:07:25