0

我使用了可扩展列表视图,我有术语列表及其解释,但是在单击术语时,我会多次得到解释..我附上了照片,所以你可以理解我的意思..

问题

可扩展列表视图适配器的类是

public class ExpandableAdapter extends BaseExpandableListAdapter {

private Activity context;
//private Map<String, String> termCollections;
private List<String> term;
private List<String> termDetail;

public ExpandableAdapter(Activity context,
 List<String> term, List<String> termDetail) {
    Log.i("expandable called","called");
    this.context = context;
    //this.termCollections = termCollections;
    this.term = term;
    this.termDetail=termDetail;
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return null;
}

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

@Override
public View getChildView(final int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {


     String termTemp = (String) termDetail.get(groupPosition);

     TextView item=null ;

    LayoutInflater inflater = context.getLayoutInflater();

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.child_item, null);
    }

    item = (TextView) convertView.findViewById(R.id.termtv);     

    item.setText(termTemp);
    Log.i("Inside child",""+item.getText());
    return convertView;
}

@Override
public int getChildrenCount(int groupPosition) {
     return termDetail.size();
}

@Override
public Object getGroup(int groupPosition) {
    return term.get(groupPosition);
}

@Override
public int getGroupCount() {
    return term.size();
}

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

@Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }
 @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
    }


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

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.group_item,
                null);
    }
    TextView item = (TextView) convertView.findViewById(R.id.group_termtv);
    item.setTypeface(null, Typeface.BOLD);
    item.setText(laptopName);
    return convertView;
}

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

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return false;
}

}

主要活动是这个

public class Term extends Activity {
List<String> groupList;
List<String> childList;
Map<String, String> termCollection;
ExpandableListView expListView;
DbHelper db;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_term);
    db = new DbHelper(Term.this);
    createGroupList();

    createChildList();

    expListView = (ExpandableListView) findViewById(R.id.termList);
    final ExpandableAdapter expListAdapter =
   new ExpandableAdapter(this, groupList, childList);
    expListView.setAdapter(expListAdapter);

}


private void createGroupList() {

    groupList=db.getTotalTerm();

}


private void createChildList() {        

    childList= db.getTotalTermDetail();

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_term, menu);
    return true;
}

 }
4

2 回答 2

2
@Override
public int getChildrenCount(int groupPosition) {
 return termDetail.size();
}

改为

@Override
public int getChildrenCount(int groupPosition) {
 return 1;
}
于 2013-09-09T05:45:20.120 回答
0
Try using  item.setText(termDetail.get(groupPosition));
于 2013-09-07T12:27:04.963 回答