2013-02-13 42 views
1

我使用ArrayAdapter創建了ListView,其中包含項目列表。我想將此ListView添加到另一個LinearLayout,如果有人點擊它將顯示項目列表。那可以實現嗎?請任何人幫助我。如何將ListView充氣到LinearLayout中

+1

您是否嘗試以某種方式解決此問題?或者你在這裏尋找工作解決方案? – Egor 2013-02-13 08:27:58

+1

請給我們看一些代碼... – Anukool 2013-02-13 08:33:14

+0

我試過這個,但是我沒能想出一個解決方案。爲了您的許可,我創建了一個列表視圖,如鏈接http://www.ezzylearning.com/tutorial.aspx?tid=1763429。而我的問題是我想通過線性佈局誇大這個項目列表。你有沒有遇到我的問題。 – androidcodehunter 2013-02-13 08:40:22

回答

0

你有一個OnClickListener在監聽器添加到您的LinearLayout,然後就出來這個:

LinearLayout lr = (LinearLayout)findViewById(R.id.yourLinearlayout); 
lr.addView(Listview); 
+0

您的解決方案不適用。其實我想膨脹在linearlayout listview項目。 – androidcodehunter 2013-02-13 11:28:53

+0

好吧我明白知道 – 2013-02-13 13:36:02

+0

其實在經過大量的研究後我終於得到了答案。我創建了一個ListView,並且當我點擊一個按鈕時,我想將其顯示爲一個虛幻的視圖。要做到這一點,只需在menifest文件中添加一行,用於將列表顯示爲對話框。這裏是行 android:theme =「@ android:style/Theme.Dialog」 謝謝所有幫助我很多。 – androidcodehunter 2013-02-13 14:55:13

0

所以我想你只需要您Iten的文本創建一個TextView,然後將其添加到您的LinearLayout:

public void onListItemClick(ListView l, View v, int position, long id) { 
    super.onListItemClick(l, v, position, id); 
    // String define above 
    strText = l.getItemAtPosition(position).toString(); 

    LinearLayout lr = (LinearLayout)findViewById(R.id.yourLinearlayout); 
    //Create a textview 
    TextView tv = new TextView(getActivity()); 
    //Set the text of the TextView with the Item Text 
    tv.setText(strText); 
    //Add it to your ListView 
    lr.addView(Listview); 


}