Android 可展开列表视图显示子组视图而不是组视图

Android 可展开列表视图显示子组视图而不是组视图,android,android-listview,Android,Android Listview,我在我的应用程序中实现了一个可扩展列表。 当我完成它时,工作完全错误。 列表中只有一行,在行标题视图中显示子数据, 这是我的密码: 我的名单: public class JoinUsAdapter extends BaseExpandableListAdapter { public static final String DESCRIPTION_TG = "description"; public static final String TITLE_TG = "title";

我在我的应用程序中实现了一个可扩展列表。 当我完成它时,工作完全错误。
列表中只有一行,在行标题视图中显示子数据,
这是我的密码:

我的名单:

public class JoinUsAdapter extends BaseExpandableListAdapter {

    public static final String DESCRIPTION_TG = "description";
    public static final String TITLE_TG = "title";
    private Context mContext;
    private List<Map<String, String>> mData;
    private LayoutInflater inflater;
    private ViewHolder vholder;

    public JoinUsAdapter(Context context, List<Map<String, String>> data) {
        this.mContext = context;
        this.mData = data;
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getGroupCount() {
        return mData.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return 1;
    }

    @Override
    public Map<String , String> getGroup(int groupPosition) {
        return mData.get(groupPosition);
    }

    @Override
    public String getChild(int groupPosition, int childPosition) {
        return mData.get(groupPosition).get(DESCRIPTION_TG);
    }

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

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

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

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.row_title_join_us, null);
            vholder = new ViewHolder();
            vholder.txtTitle = (TextView) convertView.findViewById(R.id.txtNewsTitle);
            vholder.txtShortDesc = (TextView) convertView.findViewById(R.id.txtNewsShortDesc);
            convertView.setTag(vholder);
        }
        else {
            vholder = (ViewHolder) convertView.getTag();
        }
        Map item = getGroup(groupPosition);
        vholder.txtTitle.setText(item.get(TITLE_TG).toString());
        vholder.txtTitle.setText(truncate(item.get(DESCRIPTION_TG).toString(),35)+" ...");
        return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.row_detail_join_us, null);
        }
        TextView txtLongDesc =(TextView) convertView.findViewById(R.id.txtLongDescription);
        txtLongDesc.setText(getChild(groupPosition,childPosition));
        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }
公共类JoinUsAdapter扩展了BaseExpandableListAdapter{
公共静态最终字符串描述\u TG=“DESCRIPTION”;
公共静态最终字符串TITLE\u TG=“TITLE”;
私有上下文;
私有列表数据;
私人充气机;
私人持票人;
公共JoinUsAdapter(上下文、列表数据){
this.mContext=上下文;
this.mData=数据;
充气器=(LayoutInflater)mContext.getSystemService(Context.LAYOUT\u充气器\u SERVICE);
}
@凌驾
public int getGroupCount(){
返回mData.size();
}
@凌驾
公共整数getChildrenCount(整数组位置){
返回1;
}
@凌驾
公共地图getGroup(int groupPosition){
返回mData.get(groupPosition);
}
@凌驾
公共字符串getChild(int-groupPosition,int-childPosition){
返回mData.get(groupPosition).get(DESCRIPTION\u TG);
}
@凌驾
公共长getGroupId(int-groupPosition){
返回组位置;
}
@凌驾
公共长getChildId(int-groupPosition,int-childPosition){
返回1;
}
@凌驾
公共布尔表ID(){
返回false;
}
@凌驾
公共视图getGroupView(int groupPosition、布尔isExpanded、视图convertView、视图组父级){
if(convertView==null){
convertView=充气机。充气(R.layout.row\u title\u join\u us,空);
vholder=新的视图保持架();
vholder.txtTitle=(TextView)convertView.findViewById(R.id.txtNewsTitle);
vholder.txtShortDesc=(TextView)convertView.findViewById(R.id.txtNewsShortDesc);
convertView.setTag(vholder);
}
否则{
vholder=(ViewHolder)convertView.getTag();
}
映射项=getGroup(groupPosition);
vholder.txtitle.setText(item.get(TITLE\u TG.toString());
vholder.txtitle.setText(truncate(item.get(DESCRIPTION_TG.toString(),35)+“…”);
返回视图;
}
@凌驾
公共视图getChildView(int-groupPosition、int-childPosition、布尔isLastChild、视图convertView、视图组父级){
if(convertView==null){
convertView=充气机。充气(R.layout.row\u detail\u join\u us,空);
}
TextView txtLongDesc=(TextView)convertView.findViewById(R.id.txtLongDescription);
setText(getChild(groupPosition,childPosition));
返回视图;
}
@凌驾
公共布尔值isChildSelectable(int-groupPosition,int-childPosition){
返回false;
}
以下是我的布局: 标题(作为列表行视图):


详细信息:(作为行的子级)


我找不到我的错误在哪里:/

更新:
我创建虚假数据的方法:

public void getData() {
        dataList = new ArrayList<Map<String, String>>();
        Map<String, String> item = new HashMap<String, String>();
        String fake = "We asked respondents how satisfied they are with their current job or jobs. 76% of developers report being at least satisfied with their job, and 36% love their job. Developers are generally more fulfilled by work than most employees.\n" +
                "\n" +
                "And developers in Iran are more satisfied with their jobs than developers anywhere else. Stack Overflow Careers may not have any jobs available in Iran, but you can still move there and apply for one of our many available remote jobs.";
        for(int i=0; i<10; i++) {
            item.put(JoinUsAdapter.TITLE_TG,"Title "+i);
            item.put(JoinUsAdapter.DESCRIPTION_TG,fake);
            dataList.add(item);
        }
public void getData(){
dataList=newarraylist();
Map item=newhashmap();
String fake=“我们询问了受访者对当前工作的满意度。76%的开发人员表示至少对自己的工作满意,36%的人热爱自己的工作。开发人员通常比大多数员工对工作更满意。\n”+
“\n”+
“伊朗的开发者比其他任何地方的开发者都更满意他们的工作。Stack Overflow Careers在伊朗可能没有任何工作,但你仍然可以搬到那里,申请我们提供的众多远程工作之一。”;

对于(int i=0;请显示您的输入数据,请参阅我的更新:)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <TextView
            android:id="@+id/txtLongDescription"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textColor="@color/white"
            android:text="long description long description long description long description long description long description "/>

</LinearLayout>
public void getData() {
        dataList = new ArrayList<Map<String, String>>();
        Map<String, String> item = new HashMap<String, String>();
        String fake = "We asked respondents how satisfied they are with their current job or jobs. 76% of developers report being at least satisfied with their job, and 36% love their job. Developers are generally more fulfilled by work than most employees.\n" +
                "\n" +
                "And developers in Iran are more satisfied with their jobs than developers anywhere else. Stack Overflow Careers may not have any jobs available in Iran, but you can still move there and apply for one of our many available remote jobs.";
        for(int i=0; i<10; i++) {
            item.put(JoinUsAdapter.TITLE_TG,"Title "+i);
            item.put(JoinUsAdapter.DESCRIPTION_TG,fake);
            dataList.add(item);
        }