2013-01-11 97 views
0

我想根据未来条件膨胀布局:是否可能膨胀更多布局?

if (...) { 
    view = inflater.inflate(R.layout.customer_menu_item, null); 
} 
else { 
    view = inflater.inflate(R.layout.customer_menu_index, null); 
    view = inflater.inflate(R.layout.customer_menu_item, null); 
} 

布局customer_menu_index是指数函到菜单列表的插入。第二个布局插入基本菜单项。

如何在BaseAdapter中包含的方法getView(int position, View convertView, ViewGroup parentView)的一次调用中充气两种不同的布局。

回答

1

我不知道这是否会解决你的目的,但不能实现一个包含两个布局的xml文件。然后,你可以只是操纵他们的知名度,如

view = inflater.inflate(“the_layout_from_your_xml”,null);

如果(...){

view.finViewByID(R.id.customer_menu_index).setVisibility(false); 

}其他{

view.finViewByID(R.id.customer_menu_index).setVisibility(true); 

}

为你做这项工作?

+0

谢谢,你的建议解决了这个问题。具有两个分离的XML布局的解决方案更为复杂。 – misco

0

如何在BaseAdapter中包含的方法getView(int position, View convertView, ViewGroup parentView)的一次调用中充气两种不同布局。

除了设备的内存,您可以调用inflate()的次数没有限制。但是你的else块立即覆盖第一个值view,所以考虑使用不同的变量。

如果你打算使用多列布局,您必须重写getItemViewType()getViewTypeCount()方法,否则你会看到奇怪的行为,同时滚动你的ListView控件,微调等

+0

你是对的,没有限制。但第二个电话覆盖了我的第一个价值。 'getView'的返回值是膨胀的View,所以我应该将视图充满到相同的变量。 – misco