2

비슷한 스레드를 검색했지만 도움이되지 않았지만 가벼워 졌거나 아직 대답이 없으므로 문제를 설명 할 것입니다. GetChildView가 호출되지 않았습니다.

은 내가 custom ExpandableListAdapterExpandableListView을하고 난 내 Groups하지만 Children 내를 표시 할 수 있습니다. GetChildView 어쨌든 호출되지 않습니다.

귀하의 도움에 감사드립니다.

편집 :이 섹션

... 
client = (ExpandableListView)row.findViewById(R.id.field_expandable_list); 
client.setFocusable(false);     
client_adapter = new ClientAdapter(context, titles, allFields); 
client.setAdapter(client_adapter); 

Log.i("TAG", "WmsMApActivity::doClient:: Adapter #children: "+client_adapter.getChildrenCount(0)+ 
         " ExpListView #children: "+client.getChildCount()); 

... 

를 기록 할 경우


은, 그때

I/TAG(692): WmsMApActivity::doClient::0 Adapter #children: 13 ExpListView #children: 0

그래서, 내 어댑터 데이터 만을 얻는 것을 얻을 변하기 쉬운 client (ExpandableListView)은 올바르게 설정했지만 데이터가 있음을 인식하지 못합니다.


내 코드는 다음

홈페이지 코드

// view = Item of my ListView. We come from a OnClickItem Method 
private void doClient(View view) { 

    ArrayList<String> titles = new ArrayList<String>(); 
    titles.add("fields"); 

    ArrayList allFields = transformFarmsResult(parentItems); 

    final Context context = getApplicationContext(); 

    RelativeLayout mainLayout = (RelativeLayout) view.findViewById(R.id.relLayoutDrawer); 

    // We check whether the first item (0th position) is expanded 

    View lin_layout_field_list = view.findViewById(R.id.lin_layout_field_list); 

    if (lin_layout_field_list != null) { // Hide Field_list Layout 

     ((ViewGroup) view).removeView(lin_layout_field_list); 


    } else { 

     mainLayout = (RelativeLayout) view.findViewById(R.id.relLayoutDrawer); 

     // ----------- Inflating ExpandableListView "Fields" 


     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View row    = inflater.inflate(R.layout.field_list, null); 

     client     = (ExpandableListView)row.findViewById(R.id.field_expandable_list); 

     // Adapter Population       
     client_adapter = new ClientAdapter(context, titles, allFields);     
     client.setAdapter(client_adapter); 

     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 


     TextView title_tv = (TextView)view.findViewById(R.id.title); 
     params.addRule(RelativeLayout.ALIGN_LEFT, title_tv.getId()); 
     params.addRule(RelativeLayout.BELOW, title_tv.getId());     

     mainLayout.addView(row, params); 

     // Listview Group click listener 
     client.setOnGroupClickListener(new OnGroupClickListener() { 

      @Override 
      public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { 
       Toast.makeText(context, "Group Clicked " + groupPosition, Toast.LENGTH_SHORT).show(); 
        return false; 
       } 
     }); 

     // Listview Group expanded listener 
     client.setOnGroupExpandListener(new OnGroupExpandListener() { 

       @Override 
       public void onGroupExpand(int groupPosition) { 
       Toast.makeText(context, "Group " + groupPosition + " Expanded", Toast.LENGTH_SHORT).show(); 
       } 
      }); 

     // Listview Group collasped listener 
     client.setOnGroupCollapseListener(new OnGroupCollapseListener() { 

      @Override 
      public void onGroupCollapse(int groupPosition) { 
        Toast.makeText(context, "Group " + groupPosition + " Collapsed", Toast.LENGTH_SHORT).show();; 

       } 
      }); 

     // Listview on child click listener 
     client.setOnChildClickListener(new OnChildClickListener() { 

      @Override 
      public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { 
       // TODO Auto-generated method stub 
       Toast.makeText(context, "Group " + groupPosition + " : Child " + childPosition, Toast.LENGTH_SHORT).show(); 
       return false; 
      } 
     });      

    } 

} 

어댑터

public class ClientAdapter extends BaseExpandableListAdapter{ 

private Context context; 
//private String header_title; 
private ArrayList<String> headers; 

private ArrayList fields; 

private int groupPosition = 0; 
private LayoutInflater inflater; 

public ClientAdapter(Context context, ArrayList<String> headers, ArrayList fields) { 

    this.context  = context; 
    this.headers  = headers; 
    this.fields  = fields; 
    inflater   = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    // Just to check, whether I get correct ArrayList "fields" 
    Log.i("TAG","ClientAdapter::Constructor:: fields.size: "+fields.size()); 
    for (int i=0;i<fields.size();i++) 
     Log.i("TAG","ClientAdapter::Constructor:: field["+i+"]: "+fields.get(i).toString()); 
} 

@Override 
public int getGroupCount() { 
    // Just 1 Group 
    return headers.size(); 
} 

@Override 
public String getGroup(int groupPosition) { 
    return headers.get(groupPosition); 
} 

@Override 
public long getGroupId(int groupPosition) { 
    return groupPosition; 
} 


@Override 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 
    View view = convertView; 
    GroupHolder holder=null; 

    String title_item = getGroup(groupPosition); 

    if (view == null) {   
     holder = new GroupHolder(); 
     view = inflater.inflate(R.layout.group_client, null); 
     holder.title = (TextView) view.findViewById(R.id.client_group_title); 

     view.setTag(holder); 
    } else { 
     holder = (GroupHolder) view.getTag(); 
    } 

    holder.title.setText(title_item); 

    return view; 
} 

// Children 
@Override 
public int getChildrenCount(int groupPosition) { 
    return fields.size(); 
} 


@Override 
public Object getChild(int groupPosition, int childPosition) { 
    // TODO Auto-generated method stub 
    return fields.get(childPosition); 
} 

@Override 
public long getChildId(int groupPosition, int childPosition) { 
    return childPosition; 
} 


@Override 
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    View view = convertView; 
    ChildHolder holder; 

    Log.i("TAG", "ClientAdapter::getChildView:: 0 - parent.id: "+parent.getId()); 
    final HashMap<String,Object> field = (HashMap<String,Object>) getChild(groupPosition, childPosition); 


    if (view == null) { 
     holder = new ChildHolder(); 


     view = inflater.inflate(R.layout.child_client, null); 

     holder.title = (TextView) view.findViewById(R.id.client_child_title); 
     holder.map_icon = (ImageView) view.findViewById(R.id.client_child_icon); 
     holder.contour = (CheckBox) view.findViewById(R.id.client_child_checkbox); 

     convertView.setTag(holder); 
    } else { 
     holder = (ChildHolder) view.getTag(); 
    } 

    // Handling of Title 
    String temp =(String)field.get(Constants._FIELDNAME); 
    Log.i("TAG", "ClientAdapter::getChildView:: title: "+temp); 
    holder.title.setText((String)field.get(Constants._FIELDNAME)); 

    // Handling of Contour - If it exists! 
    if (field.containsKey(Constants._BOUNDARY)) { 
     holder.contour.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       if (((CheckBox)v).isChecked()) { 
        Toast.makeText(context, "Contour enabled", Toast.LENGTH_LONG).show(); 
        // TODO : Fade-in Contour in Graphics 
       } else { 
        Toast.makeText(context, "Contour disabled", Toast.LENGTH_LONG).show(); 
        // TODO : Fade-in Contour in Graphics      
       } 

      } 

     }); 
    } else { // If there is no Contour, remains the checkbox but it's not clickable, so, it's grey! 
     holder.contour.setFocusable(false); 
     holder.contour.setClickable(false); 
    } 

    // Handling of Map Icon 
    Bitmap bitmap_icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.gmaps_icon_24); 
    holder.map_icon.setImageBitmap(bitmap_icon); 

    // Applying gray filter if not referentiable 
    if (!field.containsKey(Constants._LATITUDE) || !field.containsKey(Constants._LONGITUDE))       
     holder.map_icon.setColorFilter(Color.GRAY);     

    holder.map_icon.setOnClickListener(new OnClickListener(){ 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      if (field.containsKey(Constants._LATITUDE) && field.containsKey(Constants._LONGITUDE)) {     
       Toast.makeText(context, "Center in Field Position", Toast.LENGTH_LONG).show(); 
      } else { 
       Toast.makeText(context, Constants.NOT_CENTRED, Toast.LENGTH_LONG).show(); 
      } 
     } 

    }); 

    return view; 
} 


@Override 
public boolean isChildSelectable(int groupPosition, int childPosition) { 
    // TODO Auto-generated method stub 
    return true; 
} 

@Override 
public boolean hasStableIds() { 
    return true; 
} 

/** Events **/ 


/** Holder Classes **/ 
private static class ChildHolder { 
    TextView title; 
    ImageView map_icon; 
    CheckBox contour; 

} 

private static class GroupHolder { 
    TextView title; 
} 

}

내 레이아웃입니다.

주요 XML. field_list.xml - ExpandableListView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/lin_layout_field_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ExpandableListView 
     android:id="@+id/field_expandable_list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" <- That's a SO advice, in order that children won't be croped. Originally wrap_content 
     android:layout_weight="1" 
     android:headerDividersEnabled="true" 
     android:divider="@color/metallic_silver" 
     android:dividerHeight="1dp"> 

    </ExpandableListView> 

</LinearLayout> 

Group_client.xml에> 레이아웃 - 각 그룹 항목에 대한> 레이아웃

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:id="@+id/lin_layout_client_group" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" >  
     <TextView 
      android:id="@+id/client_group_title" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="30dp" 
      android:text="Something" 
      android:textColor="@android:color/white" 
      android:textSize="16dp" 
      android:textStyle="normal" /> 
    </LinearLayout> 

</LinearLayout> 

child_client.xml -> 각 하위 항목

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <LinearLayout 
     android:id="@+id/lin_layout_client_child" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <CheckBox 
      android:id="@+id/client_child_checkbox" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="0.05" 
      android:checked="true" 
      android:gravity="center_vertical|center" /> 

     <TextView 
      android:id="@+id/client_child_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:padding="10dp" 
      android:text="FIELD_NAME" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@android:color/white" 
      android:layout_weight="0.90" /> 

     <ImageView 
      android:id="@+id/client_child_icon" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="0.05" 
      android:layout_margin="5dp" 
      android:gravity="center_vertical|center" 
      android:src="@drawable/gmaps_icon_24" /> 

    </LinearLayout> 

</LinearLayout> 

레이아웃 EDIT (2) : 그렇듯이 레이아웃의 문제는 없습니다. ClientAdapter , 그래서 그것은

...이 예

public class ClientActivity2 extends Activity{ 

private ExpandableListView client; 
private ClientAdapter client_adapter; 

private ArrayList children; 
private ArrayList<String> groups; 

private LayoutInflater inflater; 
private LinearLayout lin_layout_probe; 

private Context context; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.field_list); 
    context = getApplicationContext(); 

    prepareData();   
    ExpandableListView client = (ExpandableListView)findViewById(R.id.field_expandable_list); 
    client_adapter = new ClientAdapter(context, groups, children); 
    client.setAdapter(client_adapter); 
    client.expandGroup(0); 


} 

private void prepareData() { 
    children = new ArrayList(); 

    HashMap<String,Object> hm1 = new HashMap<String,Object>(); 
    hm1.put(Constants._FIELDNAME,"Child1"); 
    children.add(hm1); 

    HashMap<String,Object> hm2 = new HashMap<String,Object>(); 
    hm2.put(Constants._FIELDNAME,"Child2");  
    children.add(hm2); 

    HashMap<String,Object> hm3 = new HashMap<String,Object>(); 
    hm3.put(Constants._FIELDNAME,"Child3");  
    children.add(hm3); 


    groups = new ArrayList<String>(); 
    groups.add("Group1"); 

} 

}

이 지금은 나를 혼란 무엇을 오는에 잘 작동 나는 간단한 활동 모든 (어댑터와 같은 통화)를 테스트하는 경우 클릭 레이아웃이 기본 레이아웃에 TextView 인 경우 제대로 작동합니다.

나는이 텍스트 뷰를 클릭하면 다음과 ExpandableListView 프롬프트 제대로 GroupChildren을 채워 그들이 expandable/collapsable이다.

내가 그 ItemExpandableListView는 다음 그룹이 아이들을 채워 아닌 것을 클릭하면 내 마지막 (A ListView 항목에 포함 ExpandableListView) 포스트 hier, 그래서, ExpandableListView 프롬프트처럼 테스트합니다. GetChildView은 결코 호출되지 않습니다! (LogCat을 사용했기 때문에 완전히 확신합니다)

많은 사람들이 ListViewItems의 ExpandableListViews에서 클릭에 문제가 있었고, 제 경우가 다릅니다. TextView가 내 사용자 정의 BaseExpandableListAdapter을 통해 ExpandableListView Population을 작동하지만, ListView 항목이 아닌 것은 왜 잘 작동하는지 이해할 수 있습니다.

+0

나는 기록했는데, 대신에'getChildView'는''ListView'의'getView'에 기록됩니다. –

답변

2

내가 getChildView 방법이

... 
// Member Field 
private ExpandableListView expandable_field_list; 
... 

@Override 
public View getChildView(int groupPosition, int childPosition,boolean isLastChild, View convertView, ViewGroup parent) { 
    // TODO Auto-generated method stub 

    if (groupPosition == 1) { 
     if (expandable_field_list == null) { 
      expandable_field_list = new CustomExpandableListView(context); 

      // Here I initialize the second and third Level 
      client_adapter  = new ClientAdapter(context, groups, children); 
      expandable_field_list.setAdapter(client_adapter); 

     } else { 
      client_adapter.notifyDataSetChanged(); 
     } 
     convertView = expandable_field_list; 
    } 


    return convertView; 
} 

... 

그리고 CustomExpandableListView

public class CustomExpandableListView extends ExpandableListView { 

    private boolean expanded = true; 

    public CustomExpandableListView(Context context) { 
     super(context); 
    } 


    @Override 
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     if (isExpanded()) { 
      // View.MEASURED_SIZE_MASK represents the largest height possible. 
      int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, 
       MeasureSpec.AT_MOST); 
      super.onMeasure(widthMeasureSpec, expandSpec); 

      ViewGroup.LayoutParams params = getLayoutParams(); 
      params.height = getMeasuredHeight(); 
     } else { 
      super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
     } 
    }  


    @Override 
    protected void onDetachedFromWindow() { 
     try { 
      super.onDetachedFromWindow(); 
     } catch (IllegalArgumentException e) { 
      e.printStackTrace(); 
     } 
    } 

    public void setIsExpanded(boolean expanded) { 
     this.expanded = expanded; 
    } 

    public boolean isExpanded() { 
     return expanded; 
    }  
} 

과 같은 수정 내 첫 번째 수준 어댑터 (첫 번째 레벨 ExpandableListView위한 어댑터)에서

를 해결 그 이제 그 모습은 원하는대로

enter image description here