本文介紹了在 Android 中以編程方式生成編輯文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在開發聯系人應用程序,它添加了電子郵件地址、電話號碼.我必須在代碼本身中動態創建編輯文本.我不知道如何以及在哪里實現這個邏輯,建議任何幫助將不勝感激.
I'm developing Contact Application, which adds Email address, phone number. I have to create edit text dynamically in code itself. I don't know how and where to implement this logic, suggest any help would be grateful.
推薦答案
你可以這樣創建:
EditText myEditText = new EditText(context); // Pass it an Activity or Context
myEditText.setLayoutParams(new LayoutParams(..., ...)); // Pass two args; must be LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, or an integer pixel value.
myLayout.addView(myEditText);
這可以在 UI 線程的任何地方實現;一個點擊監聽器,一個 onCreate
方法,以及介于兩者之間的一切.
This can be implemented anywhere on the UI thread; a click listener, an onCreate
method, and everything in between.
在這個問題中有一個更通用的例子,以及這些流程的詳細介紹在此博客中一個>.
There is a more generic example in this question, and a good rundown of these processes in this blog.
這篇關于在 Android 中以編程方式生成編輯文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!