Android 在可展开列表视图中动态添加子视图项
在我的android应用程序中,我需要基于按钮点击动态添加子视图。我不知道怎么做。我分享了这个示例图像。如果有人知道,请帮助我Android 在可展开列表视图中动态添加子视图项,android,expandablelistview,Android,Expandablelistview,在我的android应用程序中,我需要基于按钮点击动态添加子视图。我不知道怎么做。我分享了这个示例图像。如果有人知道,请帮助我 在活动中实施OnChildClickListener并实施此方法 @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { //Add new c
在活动中实施OnChildClickListener并实施此方法
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
//Add new chid data in your list (ex ArrayLis or Array whatever you use)
adapter.notifyDataSetChanged() // BaseExpandableListAdapter's adapter...
return true;
}
这对你有用吗?我找到了我问题的答案。对于每个按钮,单击只需膨胀xml设计的布局。这样就可以逐个添加布局。代码在这里
LayoutInflater IInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String[] names = { "Joe", "Jane", "Herkimer" };
while (run >= 1) {
View storeitems = IInflater.inflate(R.layout.product_child_item,
null);
productCode = (TextView) storeitems.findViewById(R.id.productCode);
productName = (TextView) storeitems.findViewById(R.id.productName);
noOfQuantity = (TextView) storeitems
.findViewById(R.id.noOfQuantity);
int i = run - 1;
productCode.setText(names[i]);
linearLayout.addView(storeitems, 0);
run--;
}
我的问题和上面的链接都不同,这意味着用xml创建视图,然后单击按钮setvisibility或Goney。您的问题非常模糊,我们可以假设它是重复的。如果不是:提供更多关于不同之处/原因的详细信息,副本将被删除。engar Waseem Arain,子视图可能是10或1000,具体取决于用户。因此,这在xml中是不可能的layout@user151763810或1000,基于用户??