riskPlayGround
riskPlayGround

Reputation: 452

Expandablelistview - getting same text multiple time in child view

I have used expandablelistview, i have list of terms and its explanation, but on clicking term i'm getting explanation multiple times.. i have photo attached so you can understand what i mean..

problem

class for expandable listview adapter is

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;
}

}

and main activity is this

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;
}

 }

Upvotes: 0

Views: 932

Answers (2)

riskPlayGround
riskPlayGround

Reputation: 452

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

is changed to

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

Upvotes: 2

Rishabh Srivastava
Rishabh Srivastava

Reputation: 3745

Try using  item.setText(termDetail.get(groupPosition));

Upvotes: 0

Related Questions