0
比方說,我有一個LinearLayout,我想添加兩個視圖。第一個包含editText,另一個包含listview。我一直在嘗試java中的代碼如下:AddView error,只顯示第一個元素
EditText inputViaText;
ListView historyInput;
protected static LinearLayout askTextLayout = null;
askTextLayout = new LinearLayout(this);
askTextLayout.setVisibility(LinearLayout.VISIBLE);
askTextLayout.setOrientation(LinearLayout.HORIZONTAL);
inputViaText = new EditText(this);
LinearLayout.LayoutParams askTextParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
historyInput = new ListView(this);
LinearLayout.LayoutParams historyInputParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,70);
askTextLayout.addView(historyInput,historyInputParams);
askTextLayout.addView(inputViaText,askTextParams);
FrameLayout.LayoutParams frameAskTextParams = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
setContentView(R.layout.activity_main);
addContentView(askTextLayout, frameAskTextParams);
但是,它只是顯示我添加的第一個。所以當我編碼如下:
askTextLayout.addView(historyInput,historyInputParams);
askTextLayout.addView(inputViaText,askTextParams);
它只是顯示listView。當我編碼如下:
askTextLayout.addView(inputViaText,askTextParams);
askTextLayout.addView(historyInput,historyInputParams);
它只是顯示edittext。任何人都可以幫助我?
的onCreate方法,其中該線ID來自這個代碼? 「container =(LinearLayout)findViewById(R.id.Linear);」 –
我編輯了我的答案,檢查了這一點。 – 2014-02-24 05:01:18