나는 입니다. 첫 번째 Group
의 요소는 Buttons
입니다. Button
중 하나를 클릭 한 후 Child
보기를 제거하거나 숨기려고합니다. 나는이 코드를 다음과 같이 시도했다.Android ExpandableListView : 하위 뷰의 버튼을 클릭 한 후 그룹에서 하위보기를 제거하거나 숨기기
public class ProfileExpandableAdapter extends BaseExpandableListAdapter{
private Context context;
private ArrayList<ExpandableGroup> groups;
private ImageLoader imageLoader = AppController.getInstance().getImageLoader();
private String type = "update_user_friend", userName = "";
private JSONParser jsonParser;
private String wpedenUrl = "", TAG_SUCCESS = "success";
public ProfileExpandableAdapter(Context context, ArrayList<ExpandableGroup> groups, String userName) {
this.context = context;
this.groups = groups;
this.userName = userName;
jsonParser = new JSONParser();
wpedenUrl = context.getResources().getString(R.string.site);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<ExpandableChild> chList = groups.get(groupPosition).getItems();
return chList.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final ExpandableChild child = (ExpandableChild) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.wpedenyo_profile_expandable_group_child, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.wpedenyo_profile_group_child);
tv.setText(child.getName().toString());
String image = child.getThumbnailUrl();
if(groupPosition == 0){
NetworkImageView notifiedUserImage = (NetworkImageView) convertView.findViewById(R.id.wpedenyo_notified_friend_image);
notifiedUserImage.setVisibility(View.VISIBLE);
notifiedUserImage.setImageUrl(image, imageLoader);
Button confirmButton = (Button) convertView.findViewById(R.id.wpedenyo_profile_button_confirm);
confirmButton.setVisibility(View.VISIBLE);
Button cancelButton = (Button) convertView.findViewById(R.id.wpedenyo_profile_button_cancel);
cancelButton.setVisibility(View.VISIBLE);
confirmButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
groups.remove(child);
notifyDataSetChanged();
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
groups.remove(child);
notifyDataSetChanged();
}
});
}
return convertView;
}
public void removeChild(int groupPosition, int childPosition) {
if (getChildrenCount(groupPosition)>0 && getChildrenCount(groupPosition)-1 >= childPosition)
{
Object task = this.getChild(groupPosition, childPosition);
groups.remove(task);
this.notifyDataSetChanged();
}
}
@Override
public int getChildrenCount(int groupPosition) {
ArrayList<ExpandableChild> chList = groups.get(groupPosition).getItems();
return chList.size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
ExpandableGroup group = (ExpandableGroup) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.wpedenyo_profile_expandable_group, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.wpedenyo_profile_list_header);
tv.setText(group.getName());
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
그러나 Button
을 클릭 한 후이 Group
에서 Child
을 제거 두지. 내가 어떻게 할 수 있니? 미리 감사드립니다.
답장을 보내 주셔서 감사합니다.하지만 getChildren() 메소드를 사용하는 이유가 무엇인지 이해할 수 없습니다. 이미'group'의'child'가 있습니다. 그건 그렇고, 전체 코드는 매우 감사하겠습니다. – user3384985
자녀의 위치를 알 수 있도록 그룹의 자녀가 있어야합니다. 내가 말했듯이, groups.remove (자식)을 사용하면 기술적으로 그룹을 제거하려고 시도했습니다 (그러나 자식 인수를 사용). 또는 convertView.setVisibility (View.GONE)로 자식을 숨길 수도 있습니다. – okkko
예. 작동합니다. 'currentList.getItems(). remove (child);''getItems'가'ArrayList'를 반환하는 곳 –
user3384985