I am making a shopping list, and using ExpandableListview to achieve it and it have some group items with children in it, i made a functionality of deleting group and children and in every group there is a last child namely "add item".
Now the problem is in UI, in add item i am hiding the delete button because it doesn't make a sense.
hiding is done by passing a field to arraylist which finally fills my listview, It worked fine by checking it in a condition and assigning state accordingly but when i scroll the hidden delete button become visible and vice-versa.
i have tried lots of fixes but no luck, like using Viewholder implementation.
please somebody help me, i really need a quick solution.
if any other information is needed please ask me, and please give me the answer.
Thanks
EDIT: Sorry but i can't share some part of the code , rest is this
public class MyListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<HeaderInfo> deptList;
ShoppingListFragment ShoppingListFrag;
ArrayList<HashMap<View, Boolean>> alValues;
DatabaseHelper db;
public MyListAdapter(Context context, ArrayList<HeaderInfo> deptList,
ShoppingListFragment ownerFragment) {
this.context = context;
this.deptList = deptList;
db = new DatabaseHelper(context);
this.ShoppingListFrag = ownerFragment;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<DetailInfo> productList = deptList.get(groupPosition)
.getProductList();
return productList.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
// View vi = view;
ViewHolderChild holder = null;
DetailInfo detailInfo = (DetailInfo) getChild(groupPosition,
childPosition);
Boolean bFlag = ((DetailInfo) getChild(groupPosition, childPosition))
.getLastItem();
if (view == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.child_row, null);
holder = new ViewHolderChild();
holder.childItem = (TextView) view.findViewById(R.id.childItem);
holder.tvRemover = (TextView) view.findViewById(R.id.tv_removeItem);
view.setTag(holder);
view.setTag(R.id.childItem, detailInfo.getLastItem());
view.setTag(R.id.heading, detailInfo.getTagId());
} else {
holder = (ViewHolderChild) view.getTag();
view.getTag(R.id.childItem);
view.getTag(R.id.heading);
}
holder.childItem.setText(detailInfo.getName().trim());
Log.e("MyListAdapter, GetChildView",
"Group Pos: "
+ groupPosition
+ ", Child Pos: "
+ childPosition
+ ", Last Item Pos: "
+ ((DetailInfo) getChild(groupPosition, childPosition))
.getLastItem() + ", bflag: " + bFlag
+ ", view: " + view);
if (detailInfo.getLastItem()) {
holder.tvRemover.setVisibility(View.GONE);
}
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Checking if it is last item
if (Boolean.parseBoolean(v.getTag(R.id.childItem).toString())) {
//adding child to the corresponding group
} else {
Toast.makeText(context, " item", Toast.LENGTH_SHORT).show();
}
}
});
holder.tvRemover.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Removing child from the group
}
});
return view;
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<DetailInfo> productList = deptList.get(groupPosition)
.getProductList();
return productList.size();
}
@Override
public Object getGroup(int groupPosition) {
return deptList.get(groupPosition);
}
@Override
public int getGroupCount() {
return deptList.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isLastChild, View view,
ViewGroup parent) {
ViewHolder holder = null;
HeaderInfo headerInfo = (HeaderInfo) getGroup(groupPosition);
if (view == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.group_heading, null);
holder = new ViewHolder();
holder.heading = (TextView) view.findViewById(R.id.heading);
holder.imgdelete = (ImageView) view.findViewById(R.id.img_delete);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
LibFunctions.setTypeFace(context, holder.heading,
"AvantGardeMedium.OTF");
holder.heading.setText(headerInfo.getName().trim());
holder.imgdelete.setTag(headerInfo);
Log.e("MyListActivity", "groupPosition: " + groupPosition);
holder.imgdelete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Deleting group here
}
});
return view;
}
static class ViewHolder {
TextView heading;
ImageView imgdelete;
}
static class ViewHolderChild {
TextView tvRemover, childItem;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Please help