2013-01-07 49 views
0

我正试图在iPhone上创建类似可编辑的UITableView。以编程方式向LinearLayout追加新项目?

enter image description here

我添加了一个按钮,在列表这将是iPhone上的“+”按钮相当于末尾添加新项目,这需要用户将产品添加的列表。我的问题是,当他们选择一个我不知道如何将它添加到列表中。

<LinearLayout 
      android:key="application_preferences" 
      android:title="Applications"> 
    </LinearLayout> 

如何以编程方式在LinearLayout中追加视图?

回答

1

您可以使用addView将子视图添加到ViewGroup,但也可以考虑只使用ListView而不是LinearLayout

+0

感谢,我其实是工作的一个PreferenceScreen,我写的LinearLayout,因为我认为它会是更常见的情况。我可以在首选项屏幕中使用Listview吗? – lisovaccaro

+0

我还没有在Android中使用偏好相关的API,但是从[documentation](http://developer.android.com/reference/android/preference/PreferenceScreen.html#bind%28android.widget.ListView %29)看起来确实如此。 – kabuko

1

你的问题不是很清楚,但如果你尝试将视图添加到线性布局编程只是使用Layout Inflater

LayoutInflater localLayoutInflater =(LayoutInflater)getBaseContext().getSystemService("layout_inflater"); 
View myView = localLayoutInflater.inflate(R.layout.custom_layout, null); 
final LinearLayout ll=(LinearLayout)findViewById(R.id.linearlayoutID); 
ll.addView(myView); 
相关问题