2013-09-30 26 views
0

我希望用戶輸入從EditText和他輸入的任何他在EditText他按下提交按鈕(轉到他的輸入列表),它將打印在TextView,但如果我想有一個長列表Textview (顯示他的輸入歷史的長列表)...我可以做些什麼來讓TextView的數量像列表一樣增長,因爲用戶提交更多EditText如何增加TextView的數量?

+0

你想達到什麼裏面? –

+0

你是否想用多文本顯示列表視圖!爲每個列表項目? – ajey

+0

幫助添加您的代碼 –

回答

0

您可以在java類中動態創建TextView,然後添加到您的父視圖中。

使用類似如下:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:id="@+id/info" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 
</LinearLayout> 

那麼Java類

View linearLayout = findViewById(R.id.info); 
    LinearLayout linearLayout = (LinearLayout)findViewById(R.id.info) 


    TextView valueTV = new TextView(this); 
    valueTV.setText("hallo hallo"); 
    valueTV.setId(5); 
    valueTV.setLayoutParams(new LayoutParams(
      LayoutParams.FILL_PARENT, 
      LayoutParams.WRAP_CONTENT)); 

    linearLayout.addView(valueTV); 
+0

在運行時創建新的textview並添加到LinearLayout – Swetank