我有张贴在这里的屏幕。在此屏幕中有一个可扩展的列表视图,其中包含子项,在0位置添加按钮以添加新子项。当我再次单击子项时,视图必须可见,我可以在ADD字段按钮单击时为其添加子项。请告诉我如何做到这一点,或者如果您曾经做过,请发布代码片段。
答案 0 :(得分:0)
我认为它是多级可扩展列表视图,您可以通过在运行时添加视图并使用它来设置标记和获取标记以获取子项目可见 - 例如
private void generateList(final ArrayList<Beanclass> arrayList)
{
View view = null;
ViewHolder viewHolder;
try
{
llContainerremoveAllViews();
if (arrayList != null && arrayList.size() > 0)
{
for (int i = 0; i < arrayList.size(); i++)
{
view = LayoutInflater.from(MainActivity.this).inflate(R.layout.header_row, null, false);
viewHolder = new ViewHolder();
viewHolder.rlHeader = (RelativeLayout) view.findViewById(R.id.rlHeader);
viewHolder.imgUser = (ImageView) view.findViewById(R.id.imgUser);
viewHolder.txtName = (TextView) view.findViewById(R.id.txtName);
viewHolder.txtAddress = (TextView) view.findViewById(R.id.txtAddress);
viewHolder.llContainerChild = (LinearLayout) view.findViewById(R.id.llContainerChild);
view.setTag(viewHolder);
viewHolder.txtName.setText(arrayList.get(i).name);
viewHolder.txtAddress.setText(arrayList.get(i).business_address);
String imgUrl = arrayList.get(i).user_img_url;
if (imgUrl != null && !imgUrl.equalsIgnoreCase(""))
{
Picasso.with(MainAcitivity.this).load(imgUrl).into(viewHolder.imgUser);
viewHolder.imgUser.setScaleType(ScaleType.FIT_XY);
}
generateListChild(viewHolder.llContainerChild, arrayList.get(i).arrayListUser, arrayList.get(i).id);
ViewHolderChild holderChild = new ViewHolderChild();
holderChild.llContainerChildView = viewHolder.llContainerChild;
arrayListViewHolderChilds.add(i, holderChild);
viewHolder.rlHeaderCurrentBooking.setTag(i);
viewHolder.rlHeaderCurrentBooking.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
int pos = (Integer) v.getTag();
for (int j = 0; j < arrayList.size(); j++)
{
if (j == pos)
{
if (arrayList.get(j).expand_Flag == false)
{
arrayListViewHolderChilds.get(j).llContainerChildView.setVisibility(View.VISIBLE);
arrayList.get(j).expand_Flag = true;
}
else if (arrayList.get(j).expand_Flag == true)
{
arrayListViewHolderChilds.get(j).llContainerChildView.setVisibility(View.GONE);
arrayList.get(j).expand_Flag = false;
}
}
else
{
if (arrayList.get(j).expand_Flag == true)
{
arrayListViewHolderChilds.get(j).llContainerChildView.setVisibility(View.GONE);
arrayList.get(j).expand_Flag = false;
}
}
}
}
});
llContainerBooked.addView(view);
}
}
}
catch (Exception e)
{
e.printStackTrace();
Log.error(this.getClass().getSimpleName(), e);
Log.debug(this.getClass().getSimpleName(), e + "");
}
}