2011-12-26 54 views
2

我有一個佈局,其中有編輯文本框,如何顯示它的動態.means如果我的數據庫有10行然後10編輯文本框將出現,如果它5五將來。像這樣,我可以顯示它,請幫助我。如何動態顯示編輯文本框

謝謝

回答

0

在這種情況下,我認爲,要做到這一點最好的方法是使用一個ListView,然後通過一個CursorAdapter填充它。每個項目的佈局將是一個EditText,您將在newView()中膨脹,然後從您的光標設置所需的任何值。

舉個例子,你可以點擊這裏:http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/

希望這有助於!

0

你真的應該使用一個ListView,但incase這不是重點......這是解決方案。

有一個垂直方向的LinearLayout

LinearLayout ll_table = (LinearLayout)findViewById(R.id.ll_table); 
ll_table.addView(<Put Inflated View Here>); 

現在膨脹的視圖可以簡單的EditText上或Compilcated佈局...

了一個簡單的EditText

EditText edt = new EditText(mContext); 
edt.setText("whatever"); 
ll_table.addView(edt); 

一個複雜的佈局

View view = View.inflate(mContext,R.layout.complex_layout,null); 
ll_table.addView(view); 

不過考慮使用ListView

0

做一個的LinearLayout 像 使用此代碼和檢查

LinearLayout l1 = new LinearLayout(this); 
      l1.setOrientation(LinearLayout.VERTICAL); 
      for (int i = 0; i < 10; i++) { 
       EditText e1 = new EditText(this); 
       e1.setTag(i); 
       l1.addView(e1); 

      } 

      setContentView(l1); 
    } 

    setContentView(l1); 
-1

試試這個

<input type="text" name="name" value="<?= $_post['name'] ?>"/> 
<input type="text" name="lastname" value="<?= $_post['lastname'] ?>"/> 
....... 
.... 
.... 
.... 
etc 
+1

這是Android的問題,而不是PHP。 – 2011-12-26 10:40:11

+0

@Dimitris Makris對不起:)) – 2011-12-26 10:48:33

0

你必須要在XML文件中的線性佈局,並根據記錄使用for循環你可以動態創建edittext字段。

for (int i=0;i<records;i++) 
{ 

EditText et= new EditText(this); 

linearLyaou.addView(et); 

}