ExpandableListView不追加孩子的 [英] ExpandableListView does not append the childs

查看:248
本文介绍了ExpandableListView不追加孩子的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含电影信息的ExpandableListView。该群体是电影片名,孩子的是与这部电影(都包含在电影对象)的介质。
该ExpandableListView被显示,但只与组,当我点击它们,列表不会扩大。我调试它,我弄清楚永远不会执行的getChildView。
我正在寻找,但我不能明白为什么没有被执行此方法。

 的ArrayList< MovieMock>电影;
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);    的setContentView(R.layout.savedsyncs_content);    ExpandableListView L =(ExpandableListView)findViewById(R.id.ExpandableList_Content);    laodMockedList();    ContentExpandableListAdapter适配器=新ContentExpandableListAdapter(这一点,电影);
    l.setAdapter(适配器);
}公共类ContentExpandableListAdapter扩展BaseExpandableListAdapter {
私人的ArrayList< MovieMock>电影;
私人上下文的背景下;/ *从SavedSyncs包含电影ExpandableList。该组是电影的标题,孩子的是
 *影片的媒体和信息。
 * * /
公共ContentExpandableListAdapter(上下文的背景下,ArrayList的< MovieMock>电影){
    this.context =背景;
    this.movi​​es =电影;
}@覆盖
公共布尔areAllItemsEnabled()
{
    返回true;
}@覆盖
公共MovieMock getChild(INT groupPosition,诠释childPosition){
    // TODO自动生成方法存根
    Log.d(子,getChild:+ groupPosition);
    返回movies.get(groupPosition);
}@覆盖
众长getChildId(INT为arg0,ARG1 INT){
    // TODO自动生成方法存根
    //返回的Long.parseLong(movies.get(arg0中).getId());
    返回ARG1;
}@覆盖
公共查看getChildView(INT groupPosition,诠释childPosition,布尔isLastChild,查看convertView,父母的ViewGroup){
    MovieMock孩子=(MovieMock)getChild(groupPosition,childPosition);
    Log.d(调试,ENTRO人伊霍);
    如果(convertView == NULL){
        LayoutInflater infalInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.expandablelistcontent_child,NULL);
    }    TextView的audiotxt =(TextView中)convertView.findViewById(R.id.audio_text);
    audiotxt.setText(child.getAudio());    / *的TextView videotxt =(TextView中)convertView.findViewById(R.id.video_text);
    videotxt.setText(child.getAudio()); * /    返回convertView;
}@覆盖
公众诠释getChildrenCount(INT groupPosition){
    // TODO自动生成方法存根
    返回3;
}@覆盖
公共字符串getGroup(INT groupPosition){
    // TODO自动生成方法存根
    返回movies.get(groupPosition).getTitle();
}@覆盖
公众诠释getGroupCount(){
    // TODO自动生成方法存根
    返回movies.size();
}@覆盖
众长getGroupId(INT groupPosition){
    // TODO自动生成方法存根
    //返回的Long.parseLong(movies.get(groupPosition).getId());
    返回groupPosition;
}@覆盖
公共查看getGroupView(INT groupPosition,布尔isExpanded,
        查看convertView,父母的ViewGroup){
    字符串movieTitle =(字符串)getGroup(groupPosition);    如果(convertView == NULL){
        LayoutInflater infalInflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.expandablelistcontent_group,NULL);
    }    TextView的grouptxt =(TextView中)convertView.findViewById(R.id.C​​ontentText);    grouptxt.setText(movieTitle);    返回convertView;
}@覆盖
公共布尔hasStableIds(){
    // TODO自动生成方法存根
    返回false;
}@覆盖
公共布尔isChildSelectable(INT groupPosition,诠释childPosition){
    // TODO自动生成方法存根
    返回true;
}}

这是XML code:

集团:

 < RelativeLayout的
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的TextView
    机器人:ID =@ + ID / ContentText
    机器人:文字=内容
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =40dip
    机器人:layout_alignParentLeft =真
    机器人:layout_centerVertical =真/>
<的ImageButton
    机器人:ID =@ + ID / delete_button
    机器人:layout_width =20dip
    机器人:layout_height =20dip
    机器人:背景=@绘制/ delete_button
    机器人:layout_alignParentRight =真
    机器人:layout_centerVertical =真
    >
< / ImageButton的>< / RelativeLayout的>

孩子

 < RelativeLayout的
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / layout_audio>
    < ImageView的
        机器人:背景=@绘制/ audio_icon
        机器人:layout_height =20dip
        机器人:layout_width =20dip
        机器人:ID =@ + ID / audio_icon
        >
    < / ImageView的>
    <的TextView
        机器人:ID =@ + ID / audio_text
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=音频
        机器人:layout_toRightOf =@ ID / audio_icon
    >
    < / TextView的>
< / LinearLayout中><的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / layout_video
机器人:layout_below =@ ID / layout_audio>
< ImageView的
    机器人:背景=@绘制/ video_icon
    机器人:layout_height =20dip
    机器人:layout_width =20dip
    机器人:ID =@ + ID / video_icon>
< / ImageView的>
<的TextView
    机器人:ID =@ + ID / video_text
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=拖车
    机器人:layout_toRightOf =@ ID / video_icon
>
< / TextView的>
< / LinearLayout中>
<的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / layout_image
机器人:layout_below =@ ID / layout_video>
< ImageView的
    机器人:背景=@绘制/ IMAGE_ICON
    机器人:layout_height =20dip
    机器人:layout_width =20dip
    机器人:ID =@ + ID / IMAGE_ICON>
< / ImageView的>
<的TextView
    机器人:ID =@ + ID / Image_Text的
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:重力=center_vertical
    机器人:文字=海报
    机器人:layout_toRightOf =@ ID / IMAGE_ICON
>
< / TextView的>
< / LinearLayout中>
<的LinearLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:layout_width =WRAP_CONTENT
  机器人:layout_height =WRAP_CONTENT
  机器人:ID =@ + ID / layout_info
机器人:layout_below =@ ID / layout_image>
< ImageView的
    机器人:背景=@绘制/ INFO_ICON
    机器人:layout_height =20dip
    机器人:layout_width =20dip
    机器人:ID =@ + ID / INFO_ICON>
< / ImageView的>
<的TextView
    机器人:ID =@ + ID / INFO_TEXT
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文字=电影信息
    机器人:layout_toRightOf =@ ID / INFO_ICON
>
< / TextView的>
< / LinearLayout中>
< / RelativeLayout的>


解决方案

有关的记录,这个问题是在的ImageButton组布局。我不知道为什么,但取出我解决了这个问题。

I have an ExpandableListView containing movie information. The groups are the movie titles, the childs are the media related to this movie (all included in the Movie object). The ExpandableListView is showed but only with the groups, and when I click on them, the list does not expand. I debugged it and i figure out the getChildView is never executed. I was searching but i cant realize why this method is not being executed.

ArrayList<MovieMock> movies;
@Override
public void onCreate(Bundle savedInstanceState){    
    super.onCreate(savedInstanceState);

    setContentView(R.layout.savedsyncs_content);

    ExpandableListView l = (ExpandableListView) findViewById(R.id.ExpandableList_Content);

    laodMockedList();

    ContentExpandableListAdapter adapter = new ContentExpandableListAdapter(this, movies);
    l.setAdapter(adapter);
}

public class ContentExpandableListAdapter extends BaseExpandableListAdapter {
private ArrayList<MovieMock> movies;    
private Context context;

/*ExpandableList containing the movies from SavedSyncs. The groups are the movie's titles, the childs are 
 * the movie media and information.
 * */
public ContentExpandableListAdapter(Context context, ArrayList<MovieMock> movies){
    this.context = context;
    this.movies = movies;
}

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

@Override
public MovieMock getChild(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    Log.d("CHILD", "getChild : " + groupPosition);
    return movies.get(groupPosition);
}

@Override
public long getChildId(int arg0, int arg1) {
    // TODO Auto-generated method stub
    //return Long.parseLong(movies.get(arg0).getId());
    return arg1;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,View convertView, ViewGroup parent) {
    MovieMock child = (MovieMock)getChild(groupPosition, childPosition);
    Log.d("DEBUG", "Entro al hijo") ;
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.expandablelistcontent_child, null);
    }

    TextView audiotxt = (TextView) convertView.findViewById(R.id.audio_text);
    audiotxt.setText(child.getAudio());

    /*TextView videotxt = (TextView) convertView.findViewById(R.id.video_text);
    videotxt.setText(child.getAudio());*/

    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub
    return 3;
}

@Override
public String getGroup(int groupPosition) {
    // TODO Auto-generated method stub
    return movies.get(groupPosition).getTitle();
}

@Override
public int getGroupCount() {
    // TODO Auto-generated method stub
    return movies.size();
}

@Override
public long getGroupId(int groupPosition) {
    // TODO Auto-generated method stub
    //return Long.parseLong(movies.get(groupPosition).getId());
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    String movieTitle = (String) getGroup(groupPosition);

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.expandablelistcontent_group, null);
    }

    TextView grouptxt = (TextView) convertView.findViewById(R.id.ContentText);

    grouptxt.setText(movieTitle);

    return convertView;
}

@Override
public boolean hasStableIds() {
    // TODO Auto-generated method stub
    return false;
}

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

}

And here is the XML code:

The Group:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
    android:id="@+id/ContentText" 
    android:text="Content"
    android:layout_width="wrap_content"
    android:layout_height="40dip"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"/>
<ImageButton 
    android:id="@+id/delete_button" 
    android:layout_width="20dip" 
    android:layout_height="20dip" 
    android:background="@drawable/delete_button"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    >
</ImageButton>

</RelativeLayout>

The child:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/layout_audio">
    <ImageView 
        android:background="@drawable/audio_icon" 
        android:layout_height="20dip" 
        android:layout_width="20dip" 
        android:id="@+id/audio_icon"
        >
    </ImageView>
    <TextView
        android:id="@+id/audio_text" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Audio"
        android:layout_toRightOf="@id/audio_icon"
    >
    </TextView>
</LinearLayout>

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/layout_video"
android:layout_below="@id/layout_audio">    
<ImageView 
    android:background="@drawable/video_icon" 
    android:layout_height="20dip" 
    android:layout_width="20dip" 
    android:id="@+id/video_icon">
</ImageView>
<TextView
    android:id="@+id/video_text" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Trailer"
    android:layout_toRightOf="@id/video_icon"
>
</TextView>
</LinearLayout>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/layout_image"
android:layout_below="@id/layout_video">
<ImageView 
    android:background="@drawable/image_icon" 
    android:layout_height="20dip" 
    android:layout_width="20dip" 
    android:id="@+id/image_icon">
</ImageView>
<TextView
    android:id="@+id/image_text" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:text="Poster"
    android:layout_toRightOf="@id/image_icon"
>
</TextView>
</LinearLayout>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/layout_info"
android:layout_below="@id/layout_image">  
<ImageView 
    android:background="@drawable/info_icon" 
    android:layout_height="20dip" 
    android:layout_width="20dip" 
    android:id="@+id/info_icon">
</ImageView>
<TextView
    android:id="@+id/info_text" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Movie Information"
    android:layout_toRightOf="@id/info_icon"
>
</TextView>
</LinearLayout>
</RelativeLayout>

解决方案

For the records, the problem was the ImageButton in the group layout. I dont know why, but removing it i solved the problem.

这篇关于ExpandableListView不追加孩子的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆